![](/img/trans.png)
[英]How can I perform operations in JavaScript just like we do pipeline of operations in Java streams?
[英]how to write a javascript plugin(like jQuery) which can do string operations
我想编写一个javascript
插件,可以在其中插入字符串操作,例如substring
, replace
, trim
和自定义用户功能。
我应该从哪里开始写(如果没有这种插件)?
例如: $("my string will be this").substr("will","would",{first});
要么
$("my string will be this").replace("will","would",{fromLast,3});
http://stilldesigning.com/dotstring/将原型字符串函数移植到jQuery。 看一下代码。
您不需要JQuery-Javascript自己的内置string.replace()函数使用Regex,并且已经比您建议的示例强大得多。
newstring = mystring.replace(/will/,'would');
(替换单词的特定实例比较困难,但是使用正则表达式可以实现)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.