Yes, Stefan, I am aware what this message means, yes, Stefan, I know there are other > in the code (because there are lots of > in HTML, I actually do a lot of HTML pushing in my day job) and my question was:
Is there a better and simple way to extract a substring?
because I am aware the one I have chosen does not work.
Cthulhu is my Co-Pilot.
posted 5 years ago
Sorry, if that came over a little patronizing (a little?!?)
I got focused on fixing the issue rather than answering your actual question.
I'll continue in that line for a moment :
The substring method takes two arguments startIndex and endIndex.
Obviously your change has made it so that the endIndex calculated is before the startindex.
You could possibly fix this by using the version of the indexOf method that specifies a starting point to search from.
To answer your question: Is there a better way?
Well there is another way: Using a regular expression to capture the part you are interested in.
Using regular expressions to parse full HTML is not generally recommended, but if all you are after is the content of the meta keywords tag, then it should be something like: