在预定义的字符串之后删除字符串 [英] Remove string after predefined string

查看:42
本文介绍了在预定义的字符串之后删除字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用jquery格式化和编辑返回的rss feed(字符串)之前,我正在从RSS feed中提取内容.我正在使用 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"一词.我想隐藏"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];

这篇关于在预定义的字符串之后删除字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆