First index before a position

前端 未结 5 1979
天涯浪人
天涯浪人 2021-01-21 18:49

I have a string and index in that string, and want to get the first position of a substring before that index.

e.g., in string:

\"this is a test string tha

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-21 19:27

    Like IndexOf() where you can start, lastIndexOf also gives you a place to start from going backwards

    var myString = "this is a test string that contains other string for testing";
    var lastIndexOf = myString.LastIndexOf("string", 30);
    

    Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string.

提交回复
热议问题