How to get substring from string without split?

Warak :
String str = "internet address : http://test.com Click this!";

I want to get "http://test.com", so I wrote like this.

String[] split = str.split(" ");
for ( int i = 0 ; i < split.length ; i++ ) {
    if ( split[i].contains("http://") ) {
        return split[i];
    }
}

but I think this is ineffective. how to get that more easily?

Akceptor :

Assuming you always have the same format (some text : URL more text) this can work:

public static void main(String[] args) throws IOException {
    String str = "internet address : http://test.com Click this!";
    String first = str.substring(str.indexOf("http://"));
    String second = first.substring(0, first.indexOf(" "));
    System.out.println(second);
}

But better is regex as suggested in different answer

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=153212&siteId=1