+ 1
remove characters from a string
So there's a facebook challenge that asks users to write their name without certain letters. I decided to write this in C# so everyone wouldn't need to manually remove the letters, however, if you type repeated characters it always fails to remove 1. Use "fffffff" as an example, it'll print "f". Why? https://code.sololearn.com/ci9VR2h5DqP5/?ref=app
9 Respostas
+ 2
I think this works :D
https://code.sololearn.com/cE13xM3Yl4TV/#cs
+ 1
-1 would make string with length 1, processed in the for loop.
+ 1
Daniel Cooper I have another way to achieve character filtering using regex.
https://code.sololearn.com/cVkuXVH1Yemx/?ref=app
+ 1
Calviղ Oh, I already figured it out, I also found out you can do it inline, check out my code
https://code.sololearn.com/cZVGMlqI1mZ5/?ref=app
0
What is your expected output?
Can you Add a sample...
0
Steven M It does but why does -1 work? I'm so confused
0
Calviղ Can you make that case insensitive? That's why I didn't use regex, I couldn't figure it out, lol
0
Daniel Cooper for case insensitive, use
string filtered = Regex.Replace(name, rg, "", RegexOptions.IgnoreCase);
Chack out all the regex options here https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options
0
Daniel Cooper Interesting finding 👍