Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在寻找从给定字符串数组中获取一个项目第一次出现的索引的方法:
例如:
我有以下数组:
string[] dlimiterArray = { ":", ".", ",", " ", "-", ";" };
并且还有以下字符串:
string data = "hi hi bla bla bla user:myusername. bla bla bla";
我想第一次看到其中一个dlimiterArray 项目出现
使用String.IndexOfAny:
String.IndexOfAny
int index = data.IndexOfAny(dlimiterArray);
但是,您还需要更改dlimiterArray为 a char[],而不是 a string[]:
dlimiterArray
char[]
string[]
char[] dlimiterArray = { ':', '.', ',', ' ', '-', ';' };