c# - Replace all characters not in array -


I want to ask how can I remove all the characters from the string which is not present in the alphabet string.

I can use every character for loop to check, but I need something better with better performance because the app needs to process multiple files up to (up to ~ 200) 1 string = 1 file contents

another way is to use Regex:

  var s1 = "Hello World"; Var s2 = "abcdefghijklmno"; Var s3 = Regex.Replace (s1, "[^" + s2 + "]", ""); Console.WriteLine (S3); // helloold  

If you want all alphabet characters, you can type s2 to "az" or "AZ" You can set or "a-zA-Z" .


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -