Re: String.Replace Anomoly

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Sep 18, 8:51 am, Levidikus <james.h...@xxxxxxxxx> wrote:
Normally, I never have any problems with String.Replace(). However, I
found that I need to replace multiple instances of the character
"ª" (\xAA) with a # symbol. The input file is a simple one line
file. I read in the file into a string called strLine. Then when I
do a a simple replace ... here is what I have tried:

strLine = strLine.Replace("ª", "#"); // Doesn't replace ...

strLine = strLine.Replace(@"ª", "#"); // Doesn't replace ...

strLine = strLine.Replace(@"\xAA", "#"); // Doesn't replace ...

if (strLine.Contains(@"\xAA")) MessageBox.Show("found one"); // No
message box ...

if (strLine.Contains("ª")) MessageBox.Show("found one"); // No message
box ...

if (strLine.Contains(@"ª")) MessageBox.Show("found one"); // No
message box ...

Any ideas either what I'm doing wrong, or a better way to try to
replace is persistent character that just won't go away?

*HOW* are you reading your text file? You need to match the encoding
with the encoding of the file. In this case, you'll probably need to
read the file with UTF7 encoding unless there are the encoding
specifiers at the beginning of the file.

I tried a file (and used File.ReadAllText()) with only 0xAA characters
and it would not run the replace unless I read the file UTF7...

.


Quantcast