How do I extract a substring from a string until the second space is encountered?

后端 未结 13 1485
温柔的废话
温柔的废话 2021-02-03 23:17

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\"?

相关标签:
13条回答
  • 2021-02-04 00:05

    You could try to find the indexOf "o1 " first. Then extract it. After this, Split the string using the chars "1232.5467":

            string test = "o1 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467";
            string header = test.Substring(test.IndexOf("o1 "), "o1 ".Length);
            test = test.Substring("o1 ".Length, test.Length - "o1 ".Length);
            string[] content = test.Split(' ');
    
    0 讨论(0)
提交回复
热议问题