remove characters from a string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

29th Aug 2020, 4:03 PM
Daniel Cooper
Daniel Cooper - avatar
9 Answers
29th Aug 2020, 4:39 PM
Steven M
Steven M - avatar
+ 1
-1 would make string with length 1, processed in the for loop.
30th Aug 2020, 8:19 AM
Calviղ
Calviղ - avatar
+ 1
Daniel Cooper I have another way to achieve character filtering using regex. https://code.sololearn.com/cVkuXVH1Yemx/?ref=app
30th Aug 2020, 8:57 AM
Calviղ
Calviղ - avatar
+ 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
31st Aug 2020, 12:45 AM
Daniel Cooper
Daniel Cooper - avatar
0
What is your expected output? Can you Add a sample...
29th Aug 2020, 4:47 PM
Jayakrishna 🇮🇳
0
Steven M It does but why does -1 work? I'm so confused
30th Aug 2020, 2:03 AM
Daniel Cooper
Daniel Cooper - avatar
0
Calviղ Can you make that case insensitive? That's why I didn't use regex, I couldn't figure it out, lol
30th Aug 2020, 10:44 PM
Daniel Cooper
Daniel Cooper - avatar
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
31st Aug 2020, 12:28 AM
Calviղ
Calviղ - avatar
0
Daniel Cooper Interesting finding 👍
31st Aug 2020, 12:58 AM
Calviղ
Calviղ - avatar