I have a string and need the letters from said string.
string s = "EMA123_33"; // I need "EMA" string s = "EMADRR123_33"; // I need "EMADRR"
I am using C# in Visual Studio 2008.
Extract alphabets from a string using regex You can use the regular expression 'r[^a-zA-Z]' to match with non-alphabet characters in the string and replace them with an empty string using the re. sub() function. The resulting string will contain only letters.
The strchr() function finds the first occurrence of a character in a string. The character c can be the null character (\0); the ending null character of string is included in the search.
C isalpha() The isalpha() function checks whether a character is an alphabet or not. In C programming, isalpha() function checks whether a character is an alphabet (a to z and A-Z) or not. If a character passed to isalpha() is an alphabet, it returns a non-zero integer, if not it returns 0.
bool my_predicate(char c); Then use the std::remove_if algorithm to remove the unwanted characters from the string: std::string s = "my data"; s.
You can try this:
var myString = "EMA123_33"; var onlyLetters = new String(myString.Where(Char.IsLetter).ToArray());
please note: this version will find "e" just like "E" - if you need only upper-case letters then do something like this:
var myString = "EMA123_33"; var onlyLetters = new String(myString.Where(c => Char.IsLetter(c) && Char.IsUpper(c)).ToArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With