TheSwamp
Code Red => .NET => Topic started by: poncelet on October 01, 2011, 09:29:42 AM
-
Hello,
Is there a way to remove line feeds (empty lines) with regex?
output = Regex.Replace(output, "\r{2}", Environment.NewLine)
Code above doens't work :-(
-
Hi,
This may work :
output = Regex.Replace(output , "\n{2}", "\n");
Or this (depends on the output string):
output = Regex.Replace(output , "(\r\n){2}", "\n");
But it would be easier to reply if give some more precision, i.e. an example of 'output' string, or how do you get it...
-
I tried it but it doesn't remove line feeds.
I import an ascii file with coordinates:
1 475830.758 4199125.634
2 475834.777 4199116.911
3 475840.666 4199101.86
4 475836.718 4199110.199
i can remove them with this code:
Dim length As Long
While length <> text.Length
length = text.Length
text = text.Replace(Environment.NewLine & Environment.NewLine, Environment.NewLine)
End While
If Microsoft.VisualBasic.Right(text, 1) = Chr(10) Then
text = text.Remove(text.Length - 1)
End If
Return text
but i would like to use regex
-
Look at the second expression in my first post, it may work with a string imported from an ascii file where a new line consist in a carriage return char plus a a new line char ("\r\n").
-
I'm going to try this too
Solution:
output = Regex.Replace(output, "[\r\n]+", Environment.NewLine)
:lol:
I was trying for hours to find solution
Thank you gile!
Suddenly i got more than one options (haha!)