having trouble replacing Trademark and Registered symbol with Regex
-
I'm trying to remove the ® and ™ symbols in a string using Regex and it doesnt work for the ™ symbol. Here is some example code:
Dim s1, s2, s3 As String
Dim i As Integers1 = "Trademark" + Chr(153) + " Registered" + Chr(174) s2 = System.Text.RegularExpressions.Regex.Replace(s1, "\[\\x99\]", "(TM)") s3 = System.Text.RegularExpressions.Regex.Replace(s1, "\[\\xAE\]", "(R)") Debug.Print("Orig: " + s1) For i = 0 To s1.Length - 1 Debug.Print(" " + s1.Substring(i, 1) + " " + Asc(s1.Substring(i, 1)).ToString("X") + " " + Asc(s1.Substring(i, 1)).ToString) Next Debug.Print("S2 : " + s2) Debug.Print("S3 : " + s3)
This code seems to work for the (R) symbol, but not the (TM). However, if I use Chr(153) instead of \x99 in the regex call, the code works fine. What am I doing wrong? Thanks.
-
I'm trying to remove the ® and ™ symbols in a string using Regex and it doesnt work for the ™ symbol. Here is some example code:
Dim s1, s2, s3 As String
Dim i As Integers1 = "Trademark" + Chr(153) + " Registered" + Chr(174) s2 = System.Text.RegularExpressions.Regex.Replace(s1, "\[\\x99\]", "(TM)") s3 = System.Text.RegularExpressions.Regex.Replace(s1, "\[\\xAE\]", "(R)") Debug.Print("Orig: " + s1) For i = 0 To s1.Length - 1 Debug.Print(" " + s1.Substring(i, 1) + " " + Asc(s1.Substring(i, 1)).ToString("X") + " " + Asc(s1.Substring(i, 1)).ToString) Next Debug.Print("S2 : " + s2) Debug.Print("S3 : " + s3)
This code seems to work for the (R) symbol, but not the (TM). However, if I use Chr(153) instead of \x99 in the regex call, the code works fine. What am I doing wrong? Thanks.
chr() and asc() are ancient ANSI-oriented functions. A little experiment taught me chr(153) generates unicode character x2122. Using AscW() rather than Asc() would reveal the truth about your strings. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.