替换字符串文字 [英] replace string literal
问题描述
如何使ECMA-262 String.replace方法使用
字符串文字?
例如,如果我的字符串是 HELLO [世界] QUOT;如何让它工作
在这种情况下。
请注意我的方括号不是正则表达式语法。
谢谢,
Gary
How would one make the ECMA-262 String.replace method work with a
string literal?
For example, if my string was "HELLO[WORLD]" how would I make it work
in this instance.
Please note my square brackets are not regular expression syntax.
Thanks,
Gary
推荐答案
gary写道:
如何使ECMA-262 String.replace方法与
字符串文字一起使用?
例如,如果我的字符串是HELLO [WORLD]。在这种情况下,我将如何使其工作
请注意我的方括号不是正则表达式语法。
How would one make the ECMA-262 String.replace method work with a
string literal?
For example, if my string was "HELLO[WORLD]" how would I make it work
in this instance.
Please note my square brackets are not regular expression syntax.
尝试
alert(" hello" .replace(/ ll / i,''jj''));
字符串文字是JavaScript中的对象,不像C.
-
Ian Collins。
Try
alert("hello".replace(/ll/i, ''jj'') );
String literals are objects in JavaScript, unlike C.
--
Ian Collins.
非常感谢您的回复,但是,这并没有解决我的问题。
例如
var h =" [[ ll] o" ;;
var regx = new RegExp(h,''i'');
alert(h.replace(regx,''jj'') );
显示他[ll] o而不是他[jj] o这就是我想要的。
Gary
Ian Collins写道:
Thank you very much for the reply, however, this does not solve my
problem.
For example
var h = "he[ll]o";
var regx = new RegExp ( h , ''i'' );
alert(h.replace(regx, ''jj'') );
Displays "he[ll]o" and not "he[jj]o" which is what I want.
Gary
Ian Collins wrote:
gary写道:
如何使ECMA-262 String.replace方法与
字符串文字一起使用?
例如,如果我的字符串是HELLO [WORLD]。在这种情况下,我将如何使其工作
请注意我的方括号不是正则表达式语法。
How would one make the ECMA-262 String.replace method work with a
string literal?
For example, if my string was "HELLO[WORLD]" how would I make it work
in this instance.
Please note my square brackets are not regular expression syntax.
尝试
alert(" hello" .replace(/ ll / i,''jj''));
字符串文字是JavaScript中的对象,与C不同。
-
Ian Collins。
Try
alert("hello".replace(/ll/i, ''jj'') );
String literals are objects in JavaScript, unlike C.
--
Ian Collins.
gary写道:
请不要热门帖子!
gary wrote:
Please don''t top post!
Ian Collins写道:
Ian Collins wrote:
gary写道:
gary wrote:
如何制作ECMA-262 String.replace方法使用
字符串文字?
例如,如果我的字符串是HELLO [WORLD],那么在这种情况下,我将如何使其工作
请注意我的方括号不是正则表达式语法。
How would one make the ECMA-262 String.replace method work with a
string literal?
For example, if my string was "HELLO[WORLD]" how would I make it work
in this instance.
Please note my square brackets are not regular expression syntax.
尝试
alert(" hello" .replace(/ ll / i,''jj''));
字符串文字是JavaScript中的对象,与C不同。
Try
alert("hello".replace(/ll/i, ''jj'') );
String literals are objects in JavaScript, unlike C.
非常感谢您的回复,但是,这并没有解决我的问题。
例如
var h =" he [ll] o" ;;
var regx = new RegExp(h,''i'');
alert(h.replace(regx,''jj''));
显示他[ll] o而不是他[jj] o这就是我想要的。
Thank you very much for the reply, however, this does not solve my
problem.
For example
var h = "he[ll]o";
var regx = new RegExp ( h , ''i'' );
alert(h.replace(regx, ''jj'') );
Displays "he[ll]o" and not "he[jj]o" which is what I want.
这正是我的例子所做的。你想做什么?
-
Ian Collins。
Which is exactly what my example does. What are you attempting to do?
--
Ian Collins.
这篇关于替换字符串文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!