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

后端 未结 13 1521
温柔的废话
温柔的废话 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-03 23:44

    Just use String.IndexOf twice as in:

         string str = "My Test String";
         int index = str.IndexOf(' ');
         index = str.IndexOf(' ', index + 1);
         string result = str.Substring(0, index);
    

提交回复
热议问题