public static string[] SplitKeyValue(string keyValue)
{
var line = Clean(keyValue);
if (line == null)
{
return null;
}
string[] split = line.Split(" ".ToCharArray(), 2);
if (split.Length != 2)
{
split = line.Split("=".ToCharArray(), 2);
if (split.Length != 2)
{
throw new ArgumentException("Unable to determine Key/Value pair from line [" + line + "]. There is no space from " +
"which the split location could be determined");
}
}
var key = Clean(split[0]);
if (key == null)
{
throw new ArgumentException("No valid key could be found in line [" + line + "] to form a key/value pair");
}
var value = Clean(split[1]);
if (value == null)
{
throw new ArgumentException("No corresponding value could be found in line [" + line + "] for key [" + key + "]");
}
if (value.StartsWith("="))
{
value = Clean(value.Substring(1));
if (value == null)
{
throw new ArgumentException("No corresponding value could be found in line [" + line + "] for key [" + key + "]");
}
}
return new string[] {key, value};
}