I'm using something like this:
vb.net Code:
Dim tmp As String = RichTextBox.Text tmp = tmp.Replace("[", "{") tmp = tmp.Replace(Space(1), "_")
How do I find all the "Enters" and replace them with a "^"?
I have tried vbcrlf and chr(13), but nothing
Printable View
I'm using something like this:
vb.net Code:
Dim tmp As String = RichTextBox.Text tmp = tmp.Replace("[", "{") tmp = tmp.Replace(Space(1), "_")
How do I find all the "Enters" and replace them with a "^"?
I have tried vbcrlf and chr(13), but nothing
It's important to understand what a line break is. In Windows, the standard line break is a combination of a carriage return character (ASCII 13) and a line feed character (ASCII 10). This combination can be represent in various ways. Those who've worked with C-based languages will recognise "\r\n", which is not supported in VB. In VB you can use vbCrLf, ControlChars.CrLf, ControlChars.NewLine or Environment.NewLine. On non-Windows systems, the standard line break is a line feed character alone, which can be represented using vbLf or ControlChars.Lf.
If I remember correctly, the RichTextBox uses line feeds only for line breaks. Maybe that's a standard for RTF, I don't know, but it would explain why your searching for CR/LF or just CR didn't work: you need to search for just LF.
For completeness, what you might like to do is first trying replacing all CR/LF pairs, then replace lone LFs. That way you will be sure to get every line break regardless of whether it's the Windows or non-Windows type.
Also, why do this:when you could just do this:vb.net Code:
tmp = tmp.Replace(Space(1), "_")Also, I think that you'll find that, if your replacements involve only a single character in and out, it's probably more efficient to actually use Chars instead of Strings:vb.net Code:
tmp = tmp.Replace(" ", "_")vb.net Code:
tmp = tmp.Replace(" "c, "_"c)
Thanks for the detailed explanation. I appreciate it.
Just a little addendum...
And Environment.NewLine ... that's the point of Environment.NewLine ... it is driven by the environment. Which is why it's the recommended way to do linefeeds.Quote:
On non-Windows systems, the standard line break is a line feed character alone, which can be represented using vbLf or ControlChars.Lf.
http://msdn.microsoft.com/en-us/libr...t.newline.aspx
Also, I don't think RTF actually stores the LF character... seems I remember seeing it storing the RTF code for it {\lf} I think... or something like that... I also know there's a "para" identifier to denote paragraphs... not sure how that fits into all of this... never mind, I see you're dealing with the .Text property... in which case jmc is right... replace the LFs.Quote:
Originally Posted by MSDN
-tg