I'm trying to extract a sub string from a string with Javascript and have come up with the following: http://jsfiddle.net/bbhbz7r6/1/ for some reason however, .lastindexOf() doesn't find the last occurrence of <td class="views-field views-field-line-item-title">
but the first one... and I'm not sure what I'm doing wrong.
Asked
Active
Viewed 61 times
-1

stdcerr
- 13,725
- 25
- 71
- 128
-
4Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a *specific problem or error* and *the shortest code necessary* to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example.](http://stackoverflow.com/help/mcve) – elixenide Jan 25 '15 at 07:20
-
1look Jan's answer. you don't have to do `string.length-start`, you already found the last index at which your init-
occurs, so substring from that point to the end of the string – Arkantos Jan 25 '15 at 08:03
1 Answers
1
It is actually correct. The problem is in the second line which should be
var tail = string.substring(start, string.length);

Jan Schaefer
- 1,882
- 1
- 18
- 23