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 substring i.e ."1 . 2 To Other Mobiles" and "Total".I am doing it by following code in c#.
int startPosition = currentText.IndexOf("1 . 2 To Other Mobiles");
int endPosition = currentText.IndexOf("Total");
string result = currentText.Substring(startPosition, endPosition - startPosition);
But the problem that i am facing is "Total" is Many times in my substring..I have to read after the startPosition length to last position length i.e. "Total". How to do it?
You may use String.LastIndexOf()
Problem : you are not adding the length of the first search string
1 . 2 To Other MobilessubstringTotal
Solution :
Output:
result =>
substring
try this.
Use
LastIndexOf
:then use
IndexOf
instead:You mean this?
In the text "1 . 2 To Other Mobiles fkldsjkfkjslfklsdfjk Total";
The output will be:
fkldsjkfkjslfklsdfjk