2

Im trying to parse some html code line by line. However, when i search for a line that start with <td class="departure", i cant manage to syntax it correctly because of the string delimiter signs (") (what is the name of this sign in english anyway?) in the html. It sees two strings and departure as a variable in between.

Can anyone help me with this?

if (line.startsWith("   <td class="departure"")){

   result += Html.fromHtml(line) + " ";
}
1
  • " is called a double quote or double quotation mark Commented Jan 18, 2011 at 22:48

1 Answer 1

4

Escape that character (it's called quotes) by using \:

if (line.startsWith("   <td class=\"departure\"")){

   result += Html.fromHtml(line) + " ";
}
Sign up to request clarification or add additional context in comments.

1 Comment

and just to make it even better don't rely on the amount of spaces (can be more or less than you expect) and those quotes (are optional) make the string more of a regex "[^\<]*<td class=\"?departure\"?" EDIT: my bad, startsWith doesn't allow regex, but then I'd consider going with if(line.matches("^[^\<]*<td class=\"?departure\"?")) { ...

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.