Say I have an array of items I want to split on (this is for a page ).
I’m trying to ‘intelligently’ extract out a title, but only the relevant part.
I also dont want leading/trailing spaces.
I’m not quite sure how to go about doing this though.. without putting a bunch of loops inside of other loops.
function cleanTitle(title) {
// Extract up to first delimiter
var delims = ['|','·','-',':'];
}
I am using jquery.
I also put the delims array in order of what I feel is most important. Instead of searching the entire title for the first array item before moving on to the next, I think it should do the entire string one letter at a time… each letter of the string it will check if its contained within that array. If not, it moves on. I know a lot of urls might contain even 3 out of all 4 of these, and then it wouldnt really work well otherwise.
You can use a regex to do the work for you:
Working demo: http://jsfiddle.net/jfriend00/kxVMB/