How to check that a string contains only English

I have a string that contains values ​​such as:

string str ="Abhigyan Prakash,Primeshow,NewsPoint,NCP,Inflation,सरकार,राहुल,प्राइम शो,न्यूजप्वाइंट,कमजोर,एनसीपी,अभिज्ञान प्रकाश,Rahul"; 

I used the code below to convert it to a list of arrays:

  ArrayList altags = new ArrayList( str.Split(',')); 

now I want to delete all those lines from arraylist that belong to non-English language (in my context, those words written in "Hindi" should be deleted)

please invite me to check that the string is written in English (with numbers and symbols) or in another language.

NOTE. I have no problems with the general list. I can’t take it either. but please tell me how to check that a string contains only alphabets + numeric characters + Thanks

+4
source share
2 answers

If you need to filter out strings with latin characters, numeric characters and spaces, you can use regular expressions.

  var regex = new Regex("[a-zA-Z0-9 ]*"); var result = str.Split(',') .Where(s => regex.Match(s).Value == s) .ToArray(); 
+3
source

According to ascii tables, characters of English words (with numbers) should fall between ranges 48 - 57 (0-9), 65 -90 (AZ) and 97-122 (az)

You might want to add punctuation and other imported characters, for example, é (for example, from fiancé).

+3
source

Source: https://habr.com/ru/post/1336097/


All Articles