在Javascript / jQuery中删除Word之前的文本? [英] Remove Text before Word in Javascript / jQuery?

查看:41
本文介绍了在Javascript / jQuery中删除Word之前的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'在此字词之前删除内容。您好!'

'Remove stuff before this word. Hello!'

如何在javascript或jQuery中删除上述字符串中'word'之前的文本?

How can I remove the text before 'word' in the above string in javascript or jQuery?

推荐答案

使用substring结合indexOf:

Use "substring" combined with "indexOf":

var sample = 'Remove stuff before this word. Hello!';
var substr = sample.substring(sample.indexOf('word')); //substr = 'word. Hello!'

这篇关于在Javascript / jQuery中删除Word之前的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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