David Streck
David Streck

Reputation: 108

Pulling Information From A String That Is Between Two Character

I'm trying to pull information from a string that is between two characters and append it. I was able to get it to pull the first one between the specified characters but I'm having trouble getting it to output for all of them. Any Help with this would be greatly appreciated.

var $feed = "stuff I don't want: stuff to pull; stuff I don't want: stuff to pull two; stuff I don't want: stuff to pull three;";
var $startMarker = $feed.indexOf(':');
var $endMarker = $feed.indexOf(';',$startMarker);
var $text = $feed.substring($startMarker,$endMarker)
$( "div" ).append("<p>" + $text  +  "</p>");

I was also playing around with:

var $text2 = $feed.split(':')[3].split(';')[0];
$( "div" ).append("<p>" + $text2  +  "</p>");

Upvotes: 0

Views: 55

Answers (1)

Balachandran
Balachandran

Reputation: 9637

Demo

 var feed = "stuff I don't want: stuff to pull; stuff I don't want: stuff to pull two; stuff I don't want: stuff to pull three;";



     var semiSplit=feed.split(";");


        $( "div" ).append("<p>" + semiSplit[0]  +  "</p>");
        $( "div" ).append("<p>" + semiSplit[1]  +  "</p>");
        $( "div" ).append("<p>" + semiSplit[2]  +  "</p>");

need only stuff to pull Working Demo

var semiSplitLen=semiSplit.length;
for(var i=0;i<semiSplitLen-1;i++){

    var getStup=semiSplit[i].split(":");
$( "div" ).append("<p>" + getStup[1]  +  "</p>");

}

Upvotes: 1

Related Questions