Replacing '\r' in a string: .NET 1.1  
Author Message
CJW99





PostPosted: Visual C# Language, Replacing '\r' in a string: .NET 1.1 Top

Hi All,

I have an application that takes input and splits it on the '\n' character. Every carriage return however is a combination of '\r\n', therefore I am left with stray '\r' characters. I wish to remove these characters with the minimum of fuss in the .Net framework 1.1! I have already formulated a way to do this using stringbuilder.replace, however is there an easer (and more efficient) way as I will be applying this to millions of strings.

Thanks

Chris




Visual C#3  
 
 
ahmedilyas





PostPosted: Visual C# Language, Replacing '\r' in a string: .NET 1.1 Top

why dont you just replace \r with String.Empty Example...

string myString = "hi\r\n my name is bob";

myString = myString.Replace("\r", String.Empty);

string[] arraySplitString = myString.Split(new string[] {"\n"}, StringSplitOptions.RemoveEmptyEntries);

is this what you are after



 
 
CJW99





PostPosted: Visual C# Language, Replacing '\r' in a string: .NET 1.1 Top

Thats the efficent way I was after. I found that replacing a '\r' with '' caused a comile time error... But String.Empty works out,.

Thank you

Chris



 
 
Matthew Watson





PostPosted: Visual C# Language, Replacing '\r' in a string: .NET 1.1 Top

It's even more efficient to pass null instead of string.Empty as the second parameter.