tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

String splitting and ordering enlightenment

5 Mar 2013 1 mins .NET, C#, Lessons learned

Couple of years back I wrote a C# that was splitting response from server to lines. I had the data as one string and I needed to have it as array of strings, based on lines. Pretty simple, right?

The code I wrote was basically this.

response.Split(new[] { "\r", "\n", "\r\n" }, StringSplitOptions.None);

And it was working fine. Until yesterday. The server part of the solution was moved to new machine and new language. And now it started returning the exact same string, except for new lines. Now the line endings were \r\n, standard on Windows. Without too much thinking you immediately realize, the code above still works, but splits “too much”.

Of course, the fix was easy, just changing the order, having \r\n first.

Silly me. Still learning.

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at