kakopappa
kakopappa

Reputation: 5085

string.replace function bug?

string s1 = "[quote=useruk1]<p>im useruk1</p>[/quote]<p>hi  im mod1-probe</p>";
string s2 = "hi  im mod1-probe";
string s3 =  "blah blah";
string s4 = s1.Replace(s2, s3);
Console.Write(s4);

seems to be not working. Any ideas? How to solve this problem?

UPDATE:

problem was with the space, normal space ASCII value is 32 and above string ASCII value was 160 so i did a

s1 = Regex.Replace(s1, @"\u00A0", " ");

everthing worked fine ! thanks a lot guys!

Upvotes: 0

Views: 1477

Answers (5)

kakopappa
kakopappa

Reputation: 5085

problem was with the space,

normal space ASCII value is 32 and above string ASCII value was 160

so i did a

s1 = Regex.Replace(s1, @"\u00A0", " ");

everthing worked fine !

thanks a lot guys!

Upvotes: 2

ChrisBD
ChrisBD

Reputation: 9209

In order to prevent any possible misinterpretation of "/p" I would have:

string s1 = @"[quote=useruk1]<p>im useruk1</p>[/quote]<p>hi  im mod1-probe</p>";

Upvotes: 1

Ed Swangren
Ed Swangren

Reputation: 124632

It does work. I literally copied this code from your post

string s1 = "[quote=useruk1]<p>im useruk1</p>[/quote]<p>hi  im mod1-probe</p>";
string s2 = "hi  im mod1-probe";
string s3 =  "blah blah";
string s4 = s1.Replace( s2, s3 );
Console.Write( s4 );
Console.ReadLine( );

and pasted it into a new project. My result was:

"[quote=useruk1]<p>im useruk1</p>[/quote]<p>blah blah</p>"

Upvotes: 3

Himadri
Himadri

Reputation: 8876

Getting output as [quote=useruk1]<p>im useruk1</p>[/quote]<p>blah blah</p>.

Check the space between hi and im in "hi im mod1-probe" in s2 and s1

Upvotes: 3

Igor ostrovsky
Igor ostrovsky

Reputation: 7392

When I run the code, the output is this:

[quote=useruk1]<p>im useruk1</p>[/quote]<p>blah blah</p>

Isn't that what you'd expect?

Edit: Ah yeah... as Paul points out, space vs. tab would explain it.

Upvotes: 3

Related Questions