Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a string within another string, search backwards [duplicate]

Tags:

int d; d = some_string.IndexOf("something",1000); 

I want indexOf to search some_string, starting at position 1000 and searching backwards. is this possible?

like image 254
Alex Gordon Avatar asked Apr 13 '10 21:04

Alex Gordon


1 Answers

How about LastIndexOf?

From MSDN:

Reports the index position of the last occurrence of a specified String within this instance...The search begins at the startIndex character position of this instance and proceeds backwards towards the beginning until either value is found or the first character position has been examined.

int index = some_string.LastIndexOf("something", 1000); 
like image 136
Zach Johnson Avatar answered Nov 18 '22 18:11

Zach Johnson