String.Split is convenient for splitting a string with in multiple part on a delimiter.
How should I go on splitting a string only on the first delimiter. E.g. I’ve a String
"Time: 10:12:12\r\n"
And I’d want an array looking like
{"Time","10:12:12\r\n"}
The best approach depends a little on how flexible you want the parsing to be, with regard to possible extra spaces and such. Check the exact format specifications to see what you need.
Will limit you two 2 substrings. However, this does not trim the space at the beginning of the second string. You could do that in a second operation after the split however.
Should work, but will break if you’re trying to split a header name that contains a space.
Will do exactly what you describe, but actually requires the space to be present.
Makes the space optional, but you’d still have to
TrimStart()in case of more than one space.To keep the format somewhat flexible, and your code readable, I suggest using the first option: