How to check repeated letters in a string c#

前端 未结 10 579
太阳男子
太阳男子 2020-12-21 01:39

I am creating a program that checks repeated letters in a string.

For Example:

wooooooooooow
happpppppppy

This is my

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 02:01

    You can change your loop condition to have the -1 (as others have already pointed out), or you can do it the cool kid way.

    var text = "wooooooooooow happpppppppy";
    var repeats = text.Zip(text.Skip(1), (a, b) => a == b).Count(x => x);
    

提交回复
热议问题