I want to check a string which starts with http://
or not. How can I do that without loop? Thanks in advance.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
use public boolean startsWith(String prefix)
in String API
eg : boolean isStartsWith = YOUR_STRING.startsWith("http://");
String tst = "http://web.com";
System.out.print(tst.startsWith("http://")); //prints true
回答2:
You can basically use the simplest method... i.e methods provided with the String API..
public boolean startsWith(String prefix, int toffset)
or
public boolean startsWith(String prefix)
For example :
String str = new String("http://www.google.com");
str.startsWith("http://");
It returns true if the condition is met else will return false.