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.
yourString.Split(new char[] { ':' }, 2)
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.
yourString.Split(new char[] { ':', ' ' }, 2,
StringSplitOptions.RemoveEmptyEntries)
Should work, but will break if you're trying to split a header name that contains a space.
yourString.Split(new string[] { ": " }, 2,
StringSplitOptions.None);
Will do exactly what you describe, but actually requires the space to be present.
yourString.Split(new string[] { ": ", ":" }, 2,
StringSplitOptions.None);
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:
string[] split = yourString.Split(new char[] { ':' }, 2);
// Optionally check split.Length here
split[1] = split[1].TrimStart();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…