Add http://www. in the text if not Exist

前端 未结 6 629
迷失自我
迷失自我 2021-02-08 21:31

How can I know that some text contain \"http://www.\" I want to show domain in Web View. Domain name is written in TextView but there is no restriction to add prefix. If user di

6条回答
  •  粉色の甜心
    2021-02-08 22:06

    As Sebastien requested, regex is a good option. You can also get the text from the view, create an URI object

    Uri uri = Uri.create(view.getText().toString());
    

    then with uri.somemethod You should be able to get everything about an url you want to know. If the uri fails to create, you generate error messages cause something has gone wrong.

提交回复
热议问题