C#: finding instances of a string within a string

前端 未结 5 1491
心在旅途
心在旅途 2021-01-28 01:28

Suppose I had the string \"1 AND 2 AND 3 OR 4\", and want to create an array of strings that contains all substrings \"AND\" or \"OR\", in order, found within the string.

<
5条回答
  •  灰色年华
    2021-01-28 01:57

    Since you know the exact substring you're looking for... why not just use IndexOf(substr, iOffset) to know the number of occurances (loop till it returns -1) ??

    Depending on the complexity of your task, it could be simpler/faster than using regular expressions (since you're not matching patterns).

提交回复
热议问题