1

The following console app works fine:

class Program
{
    static void Main(string[] args)
    {
        string plainx = "‘test data’ random suffix";
        plainx = Regex.Replace(plainx, @"‘", string.Empty);
        Console.WriteLine(plainx);
    }
}

However its giving me trouble in an ASP.Net application.. I am attaching a screenshot of the VS Debug watch window and Immediate window

(Click for larger view)
enter image description here

As you can see, the Regex.Replace in the Immediate Window works - but somehow it is not working in the code (line 71). I've also used String.Replace without success.

Edit It seems the value that was stored in the DB is something than what the editor shows... kind of weird.. enter image description here

Sekhar
  • 5,614
  • 9
  • 38
  • 44
  • 1
    You shouldn't be using `Regex`. – SLaks Dec 02 '13 at 21:41
  • what is the language used in your code – BRAHIM Kamel Dec 02 '13 at 21:43
  • 1
    What if you tried replacing `"\u2018"`? – Scott Chamberlain Dec 02 '13 at 21:46
  • Try looking at `testx` and `testy` in the Watch window to see what the values are after your changes. Also, what is the expected result? How do you know that the result is wrong? – Daniel Gabriel Dec 02 '13 at 21:47
  • Hi @SLaks I've also used string's Replace method in lines 68/69.. I will paste that code in the Edit shortly.. – Sekhar Dec 02 '13 at 21:49
  • @JulieShannon - the language is C# – Sekhar Dec 02 '13 at 21:49
  • @DanielGabriel - testx still contains the leading apostrophe ("‘test data’ random suffix"). I want that ‘ to be removed so that the sorting works in the intended way.. – Sekhar Dec 02 '13 at 21:51
  • @ScottChamberlain - that worked! - what do you think might be the issue? – Sekhar Dec 02 '13 at 21:55
  • The quote in your code is not the same quote in the string you are testing. I just used the hex value returned from `testx[0]` to guarantee that we are using the correct quote. Added it as an answer. – Scott Chamberlain Dec 02 '13 at 21:57
  • @ScottChamberlain.. all through the code I've used the copy-paste from the watch and debug windows to get the [‘] - I haven't typed it anywhere (In fact I don't yet know how to type that from a standard windows keyboard)... Also worrying was how the same code in the "Immediate Window" was removing the character.. – Sekhar Dec 02 '13 at 22:01
  • Thanks everyone for helping! – Sekhar Dec 02 '13 at 22:36

3 Answers3

4

Have you actually examined the text being compared? What Unicode code points does it contain?

Your code shows you trying to replace the glyph '‘', which is a left "smart quote". The character's name is LEFT SINGLE QUOTATION MARK and its code point is 0x2018 (aka '\u2018'). This is a character you can't ordinarily enter on a keyboard.

What you are probably seeing is the glyph '`', a "backtick". Its character name is GRAVE ACCENT and its code point is 0x0060 (aka '\u0060'). This is the character typed when you press the [unshifted] tilde key on a standard US keyboard (leftmost key on the number row).

It might, of course, be any of a number of other characters whose glyph is similar to a single quote. See Commonly Confused Characters for more information.

Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135
2

The single quote in your code is not the same single quote in the string you are testing.

Use the hex value returned from testx[0] directly to guarantee that we are using the correct quote.

plainx = Regex.Replace(plainx, "\u2018", string.Empty);
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
0

try to replace :

@"‘" to @"\‘"

code :

string plainx = "‘test data’ random suffix";
plainx = System.Text.RegularExpressions.Regex.Replace(plainx, @"\‘", string.Empty);
Console.WriteLine(plainx);
Console.Read();