alphabet Filter in C#?

hey if I wanted to filter out all non alphabetic input from two textboxs (aka punctuation marks, spaces, numbers) so I can compare that they have the same letters. I would filter them before I put the strings into the two arrays right? also does anybody know any properties that could help? I was thinking .CharToArray but idk what else before I sort the arrays
4 Replies
bryvee
bryvee8mo ago
Assuming I am understanding your request - This sounds like a perfect case for a regular expression. Read up on them here: https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=net-8.0 I'll save you some time and give you a hint; the expression string to match all alphabetic characters is [a-zA-Z] You can inverse the match (get the punctuation, spaces, etc..) with this expression string [^a-zA-Z] If you are confused by this, take a look at this page. https://regexone.com/ I recommend the interactive tutorial.
Regex Class (System.Text.RegularExpressions)
Represents an immutable regular expression.
RegexOne - Learn Regular Expressions - Lesson 1: An Introduction, a...
RegexOne provides a set of interactive lessons and exercises to help you learn regular expressions
Plerx
Plerx8mo ago
Depending on how perfomant your input has to be you could use searchvalues
Joschi
Joschi8mo ago
It depends a bit on the use case. But if you just want the basic latin alphabet, I would use SearchValues<T>. If you need to also support other alphabets and maybe other special language dependent characters like ä you will probably have to be more creative.
Edgar_Never_Forever
Hey thanks for the advice and the reg ex thing but I remembered ASCII and how each character has value associated with it. So I just did .ToUpper.ToCharArray with the users input then used if statement’s >= 65 (A) and <= 90 (Z) in a foreach loop to filter out the letters
Want results from more Discord servers?
Add your server