0

Possible Duplicate:
How do I split a string with any whitespace chars as delimiters?

<div class="listPrice" style="font-size: 12px; padding: 10px 0 0 0;"> HSN Price:&nbsp;$9.95 </div>

Hi i am trying to split this with its' spaces but " " is making some problem for me. I am writing code at java with using jsoup. I send element.text().split(" "); but this or element.text().split("&nbsp;"); cant execute at " " Cn you help me about this situation?

Community
  • 1
  • 1
Erçin Akçay
  • 1,383
  • 4
  • 18
  • 34
  • was good solution for whitespaces but i need execute this for a html element. – Erçin Akçay Jul 02 '12 at 10:40
  • What info are you trying to extract? – Keppil Jul 02 '12 at 10:43
  • Could you tell us more why split(" ") is bad for you because `" " is making some problem for me` is kind of vague – Pshemo Jul 02 '12 at 10:44
  • i need to extract price value only and just trying to split that text but it comes with " " so i am asking this value have a special char name or something for split ? so i only need $9.95 – Erçin Akçay Jul 02 '12 at 10:45
  • @Pshemo i just encounter with this problem my element.text() value is "HSN Price: $199.00" for this but i cant split this with using str.split(" "); – Erçin Akçay Jul 02 '12 at 10:51

1 Answers1

0

If the price is what you are after you could try with something like

Matcher matcher = Pattern.compile("(\\$.*)\\s*</div>").matcher(element.text());
String price = null;
if (matcher.find()) {
  price = matcher.group(1);
}
Keppil
  • 45,603
  • 8
  • 97
  • 119