Reputation: 75
I want to remove all non-Hebrew characters from a string (including numbers and special characters). For example: myString = "/43davcשלום דד";
I need the string to only be the Hebrew characters with spaces: "שלום דד". I also would like to put all the words from the string into an array of Strings.
I tried to use Regex but I can't make it work...
Thanks in advance!
Upvotes: 0
Views: 948
Reputation: 1107
Here is some code. Have the alphabet and check each Letter to see if it is Hebrew.
string hebrewAlphabet = "אבגדהוזחטיכךלמנסעפצקרשתםןףץ";
string FilterText (string input){
string output = "";
foreach (char letter in input){
if (hebrewAlphabet.indexOf( letter ) > 0){
output += letter;
}
}
return ouput;
|
Upvotes: 2
Reputation: 14231
If you want regular expressions, you can use Character classes.
string myString = "/43davcשלום דד";
var result = Regex.Replace(myString, @"\P{IsHebrew}", string.Empty);
Upvotes: 1