String splitting
-
I have a string that whenever it finds \r\n in the string i need it to be split, i tried using Text.Split("\r\n") but it doesnt like that. This is the only thing that is causing me errors with my printing, can anyone help me fix this? or does anyone know how i can count the number of times that \r\n appears in a string?
-
I have a string that whenever it finds \r\n in the string i need it to be split, i tried using Text.Split("\r\n") but it doesnt like that. This is the only thing that is causing me errors with my printing, can anyone help me fix this? or does anyone know how i can count the number of times that \r\n appears in a string?
Right after i posted this i had an epiphany, i just replaced \r\n in the string with ` and split using that becasue i i was trying to find an odd character that no one uses very often and that solved my problem
-
Right after i posted this i had an epiphany, i just replaced \r\n in the string with ` and split using that becasue i i was trying to find an odd character that no one uses very often and that solved my problem
You don't have to reserve a special character, just use text.Replace("\r", "").Split("\n")
-
I have a string that whenever it finds \r\n in the string i need it to be split, i tried using Text.Split("\r\n") but it doesnt like that. This is the only thing that is causing me errors with my printing, can anyone help me fix this? or does anyone know how i can count the number of times that \r\n appears in a string?
-
Hello, Instead, you should use:
Text.Split(System.Environment.NewLine);
All the best, Martin
I do not agree. First of all, System.Environment.NewLine results in a string, but String.Split requires a char or char array. Second, the logic you follow is correct only if the system that generates the file, and the system that processes the file, both have the same opinion on how to terminate lines. e.g. if you generate the file on Linux, and want to process it on WinXP, it would not work. :)
Luc Pattyn
-
I do not agree. First of all, System.Environment.NewLine results in a string, but String.Split requires a char or char array. Second, the logic you follow is correct only if the system that generates the file, and the system that processes the file, both have the same opinion on how to terminate lines. e.g. if you generate the file on Linux, and want to process it on WinXP, it would not work. :)
Luc Pattyn
I do agree with you in every point.
Luc Pattyn wrote:
First of all, System.Environment.NewLine results in a string, but String.Split requires a char or char array.
I shout test before I post!
Luc Pattyn wrote:
Second, the logic you follow is correct only if the system that generates the file, and the system that processes the file, both have the same opinion on how to terminate lines.
It's not important in the application I'm working on, but it's good to inform about that it's possibility! Thanks All the best, Martin