How to Read Substrings based on Length of the String in C#

前端 未结 5 1637
有刺的猬
有刺的猬 2021-01-23 16:06

I have a String which contains a substrings One of them is \"1 . 2 To Other Mobiles\" and other is \"Total\".Now as per my requirement i have to read the Contents between first

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 16:58

    You mean this?

    string currentText = "1 . 2 To Other Mobiles fkldsjkfkjslfklsdfjk  Total";
    string text = "1 . 2 To Other Mobiles";
    int startPosition = currentText.IndexOf("1 . 2 To Other Mobiles");
    int endPosition = currentText.IndexOf("Total");
    string result = currentText.Substring(startPosition + text.Length, endPosition - (startPosition + text.Length));
    

    In the text "1 . 2 To Other Mobiles fkldsjkfkjslfklsdfjk Total";

    The output will be:

    fkldsjkfkjslfklsdfjk

提交回复
热议问题