weird string problem

  • Thread starter Thread starter Boni
  • Start date Start date
B

Boni

Dear all,

I need to replace in a long string all chr(10) to chr(10)chr(13) if 13 is
not behind 10.

dim str as string=....

If str.Chars(i) = vbLf And str.Chars(i + 1) <> vbCr Then

str.Insert(i, vbCr)

i = i + 1

End If



But if set a breakpoint on insert and look on str before and after insert I
can see, that vbCr is just not inserted!!! ascii(str.Chars(i) ) and
str.Chars(i+/-1) are not 13!!!

What is wrong??

Thanks,

Boni
 
Hi,

String.Insert doesn't change the original string (as well as other
String methods), but generates a new
one instead.

So,
1. Use str = str.Insert(i,vbCr) - or -
2. Use StringBuilder for that.

BTW, have you considered using RegEx for this kind of job? It's pretty
simple:
str = System.Text.RegularExpressions.Regex.Replace(str, "\x0a(?!\x0d)",
Chr(10) & Chr(13))

Roman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top