kiss my armpit
kiss my armpit

Reputation: 3519

How to detect the existence of non Latin characters in a string?

I want to change all filenames containing non Latin characters to a random unique Latin string. But how can I detect the existence of non Latin character in the original filenames?

Edit

The non-latin characters might be chinese, japanese, korean, arabic, umlaut, etc characters.

Upvotes: 3

Views: 4159

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125630

You could use regex:

if(Regex.IsMatch(input, "[^a-zA-Z]"))
{
    // non-latin found
}

It will work for every letter different then a to z and A to Z.

If you'd like to allow digits too, use following: [^a-zA-Z0-9].

Non-regex solution

You could use LINQ as well, because string implements IEnumerable<char>:

if(input.ToLower().Any(c => c <= 'a' || c >= 'z'))
{
    // non-latin found
}

Upvotes: 6

Related Questions