Get index of nth occurrence of char in a string

后端 未结 9 1827
情书的邮戳
情书的邮戳 2020-12-06 00:44

I\'m trying to make a function that returns the index of the Nth occurrence of a given char in a string.

Here is my attempt:

private int IndexOfNth(s         


        
9条回答
  •  無奈伤痛
    2020-12-06 01:06

    Instead of creating a bunch of substrings, why not use the IndexOf overload that takes a starting index? This will be both easier (you won't have to adjust the final index) and more efficient (you don't have to allocate a bunch of substrings).

提交回复
热议问题