我在该字符串中有一个字符串和索引,并希望在该索引之前获得子字符串的第一个位置。
例如,在字符串中:
"this is a test string that contains other string for testing"
是否有这样的职能:
"string"和起始位置53;以及"string"和起始位置30?发布于 2015-07-01 18:08:39
与IndexOf()一样,lastIndexOf也为您提供了一个从后退开始的位置。
var myString = "this is a test string that contains other string for testing";
var lastIndexOf = myString.LastIndexOf("string", 30);报告此实例中指定字符串的上一次出现的基于零的索引位置。搜索从指定的字符位置开始,然后返回到字符串的开头。
发布于 2015-07-01 18:05:06
试一试如下:
var res = yourString.Substring(0, index).LastIndexOf(stringToMatch);发布于 2015-07-01 18:05:43
所以你想要在给定索引之前的最后一个索引.
var myString = "this is a test string that contains other string for testing";
myString = String.SubString(0, 53);
var lastIndexOf = myString.LastIndexOf("string");https://stackoverflow.com/questions/31168490
复制相似问题