Reputation: 53866
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("'"));
Upvotes: 0
Views: 95
Reputation: 1725
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());
}
Upvotes: 2
Reputation: 36349
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.
Upvotes: 2
Reputation: 32969
If myString = "www.google.com','..."
You could do:
result = myString.substring(0, myString.indexof("'");
Upvotes: 2