Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 didn't enter it I have to add and display URL in webview.

like image 769
Krishnakant Dalal Avatar asked May 18 '12 09:05

Krishnakant Dalal


1 Answers

You can do like this

String url = textView.getText().toString();
if(!url.startsWith("www.")&& !url.startsWith("http://")){
  url = "www."+url;
}
if(!url.startsWith("http://")){
  url = "http://"+url;
}

You can use this url to display content in WebView

Hope this will solve your problem

like image 184
silwar Avatar answered Sep 27 '22 19:09

silwar