Finding multiple indexes from source string

后端 未结 4 1571
眼角桃花
眼角桃花 2021-01-12 21:23

Basically I need to do String.IndexOf() and I need to get array of indexes from the source string.

Is there easy way to get array of indexes?

Before asking t

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 21:55

    You would have to loop, I suspect:

            int start = 0;
            string s = "abcdeafghaji";
            int index;
            while ((index = s.IndexOf('a', start)) >= 0)
            {
                Console.WriteLine(index);
                start = index + 1;
            }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题