Delete row after predefined row

I pull the content out of the RSS feed before using jquery to format and edit the rss returned string (s). I use replace to replace strings and characters as follows:

 var spanish = $("#wod a").text(); var newspan = spanish.replace("=","-"); $("#wod a").text(newspan); 

This works great. I am also trying to delete all text after a certain point. Like truncation, I would like to hide the entire text, starting with the word "Example".

In this particular RSS feed, an example of a word is in each feed. I would like to hide the "example" , and all the text follows that word. How can i do this?

+8
javascript replace
source share
4 answers

Although jQuery is not enough, you donโ€™t even need to delete it after a certain word in a given line. The first approach is to use substring :

 var new_str = str.substring(0, str.indexOf("Example")); 

The second is the split trick:

 var new_str = str.split("Example")[0]; 
+20
source share

If you also want to save the โ€œExampleโ€ and simply delete everything after this particular word, you can do:

 var str = "aaaa1111?bbb&222:Example=123456", newStr = str.substring(0, str.indexOf('Example') + 'Example'.length); // will output: aaaa1111?bbb&222:Example 
+4
source share

I would like to hide all text starting with the word "Example"

A solution that uses a simpler replacement of links to feedback to โ€œhideโ€ everything, starting with the word โ€œExampleโ€, but keeping the material in front of it.

 var str = "my house example is bad" str.replace(/(.*?) example.*/i, "$1") // returns "my house" // case insensitive. also note the space before example because you // probably want to throw that out. 
0
source share

All Articles