问题描述
在使用 jquery 格式化和编辑返回的 RSS 提要(字符串)之前,我正在从 RSS 提要中提取内容.我正在使用 replace
来替换字符串和字符,如下所示:
I am pulling content from an RSS feed, before using jquery to format and edit the rss feed (string) that is returned. I am using replace
to replace strings and characters like so:
var spanish = $("#wod a").text();
var newspan = spanish.replace("=","-");
$("#wod a").text(newspan);
这很好用.我还试图在某个时间点后删除所有文本.与截断类似,我想隐藏从示例"一词开始的所有文本.
This works great. I am also trying to remove all text after a certain point. Similar to truncation, I would like to hide all text starting from the word "Example".
在这个特定的 RSS 提要中,示例这个词出现在每个提要中.我想隐藏 "example"
和该单词后面的所有文本.我怎样才能做到这一点?
In this particular RSS feed, the word example is in every feed. I would like to hide "example"
and all text the follows that word. How can I accomplish this?
推荐答案
虽然没有足够的 jQuery,您甚至不需要它来删除给定字符串中某个单词之后的所有内容.第一种方法是使用substring
:
Though there is not enough jQuery, you even don't need it to remove everything after a certain word in the given string. The first approach is to use substring
:
var new_str = str.substring(0, str.indexOf("Example"));
第二个是split
的技巧:
var new_str = str.split("Example")[0];
这篇关于在预定义字符串后删除字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!