I have a string like this:
\"o1 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467\"
How do I extract only \"o1 1232.5467\"
?>
There are shorter ways of doing it like others have said, but you can also check each character until you encounter a second space yourself, then return the corresponding substring.
static string Extract(string str)
{
bool end = false;
int length = 0 ;
foreach (char c in str)
{
if (c == ' ' && end == false)
{
end = true;
}
else if (c == ' ' && end == true)
{
break;
}
length++;
}
return str.Substring(0, length);
}