0

How can I access WWW.GOOGLE.COM within this String.

I can use the substring method to chop off javascript:linkToExternalSite(' but how can I remove the subsequest string.

So that

javascript:linkToExternalSite('WWW.GOOGLE.COM','D','SDFSDX2131D','R','','X','D','DFA','SAFD')

becomes

WWW.GOOGLE.COM

This works

string = string.substring(31, string.length());
string = string.substring(0, string.indexOf("'"));
2
  • The format of linkToExternalSite is always same or it may be change the format. Commented Jan 19, 2012 at 11:50
  • 1
    google.com/search?q=url+regex - hope it helps ;) Commented Jan 19, 2012 at 11:51

4 Answers 4

2

If myString = "www.google.com','..."

You could do:

result = myString.substring(0, myString.indexof("'");
Sign up to request clarification or add additional context in comments.

Comments

2

You don't need to, there is an easier way:

final String it = "WWW.GOOGLE.COM";

No need for chop, cut or other bloody operations.

2 Comments

How is this supposed to work, are you not extracting this string by just looking at it yourself ?
You said you want to extract that from the more complex string above - yet what I've shown is there is an easier way to get the string "WWW.GOOGLE.COM"
2

Use regex

String substring = //YOURSUBSTRING
    Pattern p = Pattern.compile("[W]{3}[.A-Z]+[.COM|.CO.UK]", Pattern.CASE_INSENSITIVE);

    Matcher matcher = p.matcher(substring);

        if (matcher.find()){
            String Url = matcher.group();
            System.out.println(matcher.group());

        }

1 Comment

btw the regex is pretty basic and could be improved !
0

You Can use the substring() Method Of String Class!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.