添加http://www.在文本中(如果不存在) [英] Add http://www. in the text if not Exist

查看:92
本文介绍了添加http://www.在文本中(如果不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么知道某些文本包含"http://www".我想在Web视图中显示域.域名是用TextView编写的,但是没有添加前缀的限制.如果用户未输入,则必须在webview中添加并显示URL.

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.

推荐答案

您可以这样做

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

您可以使用此URL在WebView中显示内容

You can use this url to display content in WebView

希望这可以解决您的问题

Hope this will solve your problem

这篇关于添加http://www.在文本中(如果不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆