How to determine a string is English or Persian?

后端 未结 5 916
南笙
南笙 2021-01-11 17:45

I have edittext in a form, I want that when the user inputs text into the edittext for my program to detect which language was inserted into the edittext.

Is there a

5条回答
  •  隐瞒了意图╮
    2021-01-11 18:16

    There's no exact way to determine what language your user is typing in unless you get really complicated, hence why the method example you've given is called isProbablyArabic rather than isArabic. If your users are writing exclusively in English or Farsi and nothing else, one option is to use a regex that looks to see if the user's text contains Western Roman characters ("^[a-zA-Z]*$"), if this returns false you can assume they've typed in Persian, though it could be anything that uses a different character set.

提交回复
热议问题