0

I'm trying to replace ' with its HTML entity reference using the String.Replace function. So a'a becomes a’a which is correct, but if I try to make the inverse (from the string above back to a'a) the output is always a’a.

I've noticed that if I try to replace only the code #8217; without the & character everything works fine, so maybe that the & character is a part of the problem.

5
  • 9
    Please give us some code. Commented Dec 8, 2010 at 17:07
  • 5
    Perhaps change the title to "C# String.Replace doesn't work as I expect it" Commented Dec 8, 2010 at 17:08
  • Also, there are multiple quote-like glyphs; I wonder if is it is simply a different code-point Commented Dec 8, 2010 at 17:10
  • What is inverse method? what is a thing you want to inverse? Commented Dec 8, 2010 at 17:15
  • 2
    @Saeed, I don't think Jaxer means to call an Inverse() method. I think he means that if String.Replace() is called twice the string should be back to the way it was before String.Replace() was called the first time. Without some code it's hard to see the problem. Commented Dec 8, 2010 at 17:20

3 Answers 3

0

This code works fine:

string s0 = "a'a";
string s1 = s0.Replace("'", "’"); 
string s2 = s1.Replace("’", "'");

Could you give us more information?

Sign up to request clarification or add additional context in comments.

Comments

0

I don't know whats your problem, this little code works just perfect:

        String test = "a’a";

        Console.WriteLine(test.Replace("’", "'"));

Comments

-1

I think its is string delimiters i.e ",' are interrupting normal string delimiters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.