473,408 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

replace string literal

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

Jun 6 '06 #1
21 3344
gary wrote:
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.

Try

alert("hello".replace(/ll/i, 'jj') );

String literals are objects in JavaScript, unlike C.

--
Ian Collins.
Jun 6 '06 #2
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 wrote:
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.

Try

alert("hello".replace(/ll/i, 'jj') );

String literals are objects in JavaScript, unlike C.

--
Ian Collins.


Jun 6 '06 #3
gary wrote:

Please don't top post!
Ian Collins wrote:
gary wrote:
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.


Try

alert("hello".replace(/ll/i, 'jj') );

String literals are objects in JavaScript, unlike C.

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.

Which is exactly what my example does. What are you attempting to do?

--
Ian Collins.
Jun 6 '06 #4
Ian Collins wrote:
gary wrote:
How would one make the ECMA-262 String.replace method work
with a string literal?
<snip> Try

alert("hello".replace(/ll/i, 'jj') );

String literals are objects in JavaScript, unlike C.


No they are not. String primitive and string objects are distinct in
javascript, and string literals define string primitives.

The above works because the dot operator implicitly type-converts its
left hand side operand into an object, so the above is implicitly
equivalent to:-

alert((new String("hello")).replace(/ll/i, 'jj') );

Richard.
Jun 6 '06 #5
Richard Cornford wrote:
Ian Collins wrote:
alert("hello".replace(/ll/i, 'jj') );

String literals are objects in JavaScript, unlike C.


No they are not. String primitive and string objects are distinct in
javascript, and string literals define string primitives.

The above works because the dot operator implicitly type-converts its
left hand side operand into an object, so the above is implicitly
equivalent to:-

alert((new String("hello")).replace(/ll/i, 'jj') );


But perhaps you could clear something up for me. If I pass a string
object to a function (that may return an altered string), a reference
should be passed. So it would be more efficient, in general, to pass a
string object and have the function change the underlying string rather
than having to return the string, since returning means that the string
must be copied when there are no changes. My question is, how does one
change the string of the string object without bothering the reference?
I could always wrap the string in an array, but that doesn't seem like
it's in the right spirit.

Csaba Gabor from Vienna

In this non working example, I'd like the line in the function to
change the contents of the string object instead of changing the object
itself (which, as a result, won't be reflected in the caller).
var oStr = new String("example string")
function changeoStr (oStr) {
// possibly oStr.__parent__ or oStr.__proto__ could help?
// doesn't work. I'd just like the underlying string changed
oStr = "new string";
}
changeoStr(oStr);
alert (oStr); // I'd like the alert to show "new string"

Jun 6 '06 #6
Csaba Gabor wrote:
Richard Cornford wrote: <snip>
... . String primitive and string objects are distinct in
javascript, and string literals define string primitives.

<snip> ... . My question is, how does one change the string of the string
object without bothering the reference?

<snip>

Javascript does not have any means of changing the internal value of a
String object.

Richard.

Jun 6 '06 #7
Richard Cornford wrote:
Ian Collins wrote:
gary wrote:
How would one make the ECMA-262 String.replace method work
with a string literal?


<snip>
Try

alert("hello".replace(/ll/i, 'jj') );

String literals are objects in JavaScript, unlike C.

No they are not. String primitive and string objects are distinct in
javascript, and string literals define string primitives.

OK, thanks for pointing that out.

--
Ian Collins.
Jun 6 '06 #8
Richard Cornford wrote:
Csaba Gabor wrote:
Richard Cornford wrote:

<snip>
... . String primitive and string objects are distinct in
javascript, and string literals define string primitives.

<snip>
... . My question is, how does one change the string of the string
object without bothering the reference?

<snip>

Javascript does not have any means of changing the internal value of a
String object.


Thanks, I was afraid you might say something like that.
Well, if I can't unwrap the string object to get to the string, at
least I can wrap up the string in my own object to pretend that it's a
string object. Thus, I have a cleaner way to pass the string by
reference than wrapping it in an array. That is to say, other than a
distinct way to create it and a new in place replacement function
(.selfReplace), it appears to old code as a normal string.

I tried to modify the String object itself, similarly to the below (by
giving it a self value, to override any original value), but I didn't
get it working (yet?).

Csaba
function oString(str) {
this.__proto__ = new String(str);
this.toString = function() {return this.__proto__.toString(); };
this.valueOf = function() {return this.__proto__.valueOf(); };
this.selfReplace = function(needleRegExp, strReplacement) {
this.__proto__ = new String(this.replace(needleRegExp,
strReplacement)); } }
function changeStr (oStr, newStr) { oStr.selfReplace(/.*/, newStr); }

var oStr = new oString("my string"); alert("length: " + oStr.length);
oStr.selfReplace (/str/,"th"); alert("replaced string: " + oStr);
changeStr(oStr, "something new"); alert("changed string: " + oStr);

Jun 6 '06 #9
JRS: In article <11*********************@f6g2000cwb.googlegroups.c om>,
dated Mon, 5 Jun 2006 18:14:09 remote, seen in
news:comp.lang.javascript, gary <gb*****@gmail.com> posted :
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.


I assume that you want to use the above string as part of the RegExp, so
that a matching section can be found in a longer string.

S0 = "HELLO[WORLD]" // yours
S1 = S0.replace(/([\[\]])/g, "\\$1") // fix-up

T0 = "aaaHELLO[WORLD]cccxxxHELLO[WORLD]yyy" // test text

RE = new RegExp(S1)
T1 = T0.replace(RE, "bbb")

RE = new RegExp(S1, "g")
T2 = T0.replace(RE, "bbb")

A = [T1,,,T2] // results

No doubt you will need to fix up any other troublesome characters in S0,
by enhancing the line that gives S1.

Possibly, one could alternatively fix-up by converting characters to
Unicode???
*** DO NOT MULTI-POST ***
*** READ THE news:C.L.J FAQ ***

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 6 '06 #10
Csaba Gabor wrote:
<snip>
I tried to modify the String object itself, similarly to the
below (by giving it a self value, to override any original
value), but I didn't get it working (yet?). <snip>
function oString(str) {
this.__proto__ = new String(str);
this.toString = function() {return this.__proto__.toString(); };
this.valueOf = function() {return this.__proto__.valueOf(); };
this.selfReplace = function(needleRegExp, strReplacement) {
this.__proto__ = new String(this.replace(needleRegExp,
strReplacement)); } }
function changeStr (oStr, newStr) { oStr.selfReplace(/.*/, newStr); }

<snip>

That seems a very extension dependent method of doing what ECMAScript
should be able to do by using a String object as the prototype for
another object:-

function VariableString(st){
this.set(st);
}
VariableString.prototype = new String('');
(VariableString.prototype.toString =
(VariableString.prototype.valueOf = function(){
return this.value;
})
);
VariableString.prototype.set = function(st){
this.value = String(st);
this.length = this.value.length;
};
function changeStr(oStr, newStr){
oStr.set(oStr.replace(/.*/, newStr));
}

var t = new VariableString('yyy')
alert(t);
changeStr(t, 'xxu xxz');
alert(
t+' '+
'\nindex of u [2] = '+t.indexOf('u')+
'\nlast index of x [5] = '+t.lastIndexOf('x')+
'\nsubstring(4, -1) [xxu ] = "'+t.substring(4, -1)+'"'+
'\ncharAt(2) [u ] = "'+t.charAt(2)+'"'+
'\ncharCodeAt(3) [32] = '+t.charCodeAt(3)+
'\nconcat(" ff", 4) [xxu xxz ff4] = '+t.concat(" ff", 4)+
'\nmatch("x") [x] = "'+t.match("x")+'"'+
'\nsearch("x") [0] = '+t.search("x")+
'\nslice(2, 5) [u x] = "'+t.slice(2, 5)+'"'+
'\nsplit("x") [,,u ,,z] = '+t.split("x")+
'\ntoUpperCase() [XXU XXZ] = "'+t.toUpperCase()+'"'+
'\nlength [7] = '+t.length
);

- Or using a closure to make the string value of the object private:-

function VariableString(st){
var value;
this.toString = this.valueOf = function(){
return value;
};
this.set = function(st){
value = String(st);
this.length = value.length;
};
this.set(st);
}
VariableString.prototype = new String('');

Richard.
Jun 7 '06 #11

Dr John Stockton wrote:
JRS: In article <11*********************@f6g2000cwb.googlegroups.c om>,
dated Mon, 5 Jun 2006 18:14:09 remote, seen in
news:comp.lang.javascript, gary <gb*****@gmail.com> posted :
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.


I assume that you want to use the above string as part of the RegExp, so
that a matching section can be found in a longer string.

S0 = "HELLO[WORLD]" // yours
S1 = S0.replace(/([\[\]])/g, "\\$1") // fix-up

T0 = "aaaHELLO[WORLD]cccxxxHELLO[WORLD]yyy" // test text

RE = new RegExp(S1)
T1 = T0.replace(RE, "bbb")

RE = new RegExp(S1, "g")
T2 = T0.replace(RE, "bbb")

A = [T1,,,T2] // results

No doubt you will need to fix up any other troublesome characters in S0,
by enhancing the line that gives S1.

Possibly, one could alternatively fix-up by converting characters to
Unicode???
*** DO NOT MULTI-POST ***
*** READ THE news:C.L.J FAQ ***

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Thanks John,

Yours seems to be the cloest answer yet.

It seems strange I have to handle things like square brackets myself.

The same would be the case for all regex special characters, so in
reality its not useable to any extent without writing a function which
handles everything.

Gary

Jun 7 '06 #12
Richard Cornford wrote:
Csaba Gabor wrote:
<snip>
I tried to modify the String object itself, similarly to the
below (by giving it a self value, to override any original
value), but I didn't get it working (yet?).

<example>
That seems a very extension dependent method of doing what ECMAScript
should be able to do by using a String object as the prototype for
another object:-
<example>
- Or using a closure to make the string value of the object private:-


....

Thanks for the nice examples. But is it not possible to modify the
String prototype directly? The below code that I tried works in FF,
but it fails in IE 6: changeStr works as expected, changing .self on
the string object. However, while the revised valueOf and toString
methods fire, they do not see (this).self, and I don't see what I'm
missing either.

Csaba

function protoRevamp (obj, strMethod) {
var tmpMethod=obj.prototype[strMethod];
obj.prototype[strMethod] = function(oldMethod) {
return function() {
if (this.self || this.self=="") return this.self;
return oldMethod.apply(this); } } (tmpMethod); }

protoRevamp (String, "valueOf");
protoRevamp (String, "toString");
String.prototype.selfReplace =
function(searchRE, strReplacement) {
this.self = this.replace(searchRE, strReplacement); }

function changeStr (oStr, newStr) { oStr.selfReplace(/.*/, newStr); }

var t = new String('yyy');
alert ("old t: " + t);
changeStr(t, 'xxu xxz');
alert(
'string [xxu xxz] = "' + t+'"'+
'\nself [xxu xxz] = "' + t.self+'"'+
'\nlength [7] = '+t.length+
'\nindex of u [2] = '+t.indexOf('u')+
'\nlast index of x [5] = '+t.lastIndexOf('x')+
'\nsubstring(4, -1) [xxu ] = "'+t.substring(4, -1)+'"'+
'\ncharAt(2) [u ] = "'+t.charAt(2)+'"'+
'\ncharCodeAt(3) [32] = '+t.charCodeAt(3)+
'\nconcat(" ff", 4) [xxu xxz ff4] = '+t.concat(" ff", 4)+
'\nmatch("x") [x] = "'+t.match("x")+'"'+
'\nsearch("x") [0] = '+t.search("x")+
'\nslice(2, 5) [u x] = "'+t.slice(2, 5)+'"'+
'\nsplit("x") [,,u ,,z] = '+t.split("x")+
'\ntoUpperCase() [XXU XXZ] = "'+t.toUpperCase()+'"'
);

Jun 7 '06 #13
Csaba Gabor wrote:
Richard Cornford wrote: <snip>
That seems a very extension dependent method of doing what
ECMAScript should be able to do by using a String object as
the prototype for another object:-


<example>
- Or using a closure to make the string value of the object private:-

...

Thanks for the nice examples. But is it not possible to modify the
String prototype directly?


Why? What you are proposing is in no way simpler or more obvious/clear
that my suggestions.
The below code that I tried works in FF,
but it fails in IE 6: ...
, and I don't see what I'm missing either.

<snip>

An appreciation of simplicity apparently.

Richard.

Jun 7 '06 #14
Richard Cornford wrote:
Csaba Gabor wrote:
Richard Cornford wrote: <snip>
That seems a very extension dependent method of doing what
ECMAScript should be able to do by using a String object as
the prototype for another object:-


<example>
- Or using a closure to make the string value of the object private:-

...

Thanks for the nice examples. But is it not possible to modify the
String prototype directly?


Why?


Why do I want to know? To further my understanding. I've done
almost nothing with prototypes, and it's evident that I don't have
a sufficient grasp of them yet. You'd be one of the first people
I'd expect to support furthering such understanding.
What you are proposing is in no way simpler or more obvious/clear
that my suggestions.


Nor did I even imply it.
The below code that I tried works in FF,
but it fails in IE 6: ...
, and I don't see what I'm missing either.

<snip>

An appreciation of simplicity apparently.


No, I have a deep appreciation of simplicity. However,
without understanding, appreciation tends to be shallow.
So to fully appreciate your solution, it makes sense for
me to understand why the approach I mentioned can't
work or what it would take to shore it up.

Csaba

Jun 7 '06 #15
Csaba Gabor wrote:
Richard Cornford wrote:
Csaba Gabor wrote: <snip>
... . But is it not possible to modify the
String prototype directly?
Why?


Why do I want to know?


No, why do you want to modify the String prototype directly?

<snip> ... . You'd be one of the first people
I'd expect to support furthering such understanding.

<snip>

And you would not have been someone I would have expected to champion
top-posting.

Richard.

Jun 7 '06 #16
Richard Cornford wrote:
Csaba Gabor wrote:
Richard Cornford wrote:
Csaba Gabor wrote: <snip> ... . But is it not possible to modify the
String prototype directly?

Why?
Why do I want to know?


No, why do you want to modify the String prototype directly?


For a small incremental modification of the way an object works, it
seems reasonable to me to modify the object definition. If I want to
have a repeat method on strings ("string".repeat(nTimes)) it seems
reasonable to me to modify String.prototype instead of creating a
separate wrapped object. Since the method wasn't there before, it
doesn't lead to a decrease in efficiency, and it won't disturb older
code.

While this argument doesn't hold for what I was after, it is still
incremental modification from a user's point of view: a string object
whose underlying string is changeable. So, it's not unreasonable to
consider altering the String prototype. Whether it actually makes
sense (and is doable) is a separate issue.

That was the original reason. However, at this point the reason is
simply understanding.

What I think fails in IE is that when you try to do something like
function protoRevamp (obj, strMethod) {
var tmpMethod=obj.prototype[strMethod];
obj.prototype[strMethod] = function(oldMethod) {
return function() {
if (this.self || this.self=="") return this.self;
return oldMethod.apply(this); } } (tmpMethod); }

protoRevamp (String, "valueOf");
protoRevamp (String, "toString");
var t = new String('yyy');
t.self = "foo";
alert (t);
instead of t.toString() or t.valueOf() being directly called to
accomodate the alert, IE seems to be making a new String object based
off of t, and then making the .toSring() call on the new object.
Frankly, I don't understand the logic here - seems more like the
department of redundancy department to create a new String object.
Anyway, the new object is not a copy of t because that .self property I
put on t isn't copied over to the new object (the .selfReplace method
is on the new object, since it's on String.prototype). Therefore,
this.self doesn't refer to t.self.

Seems to me like this approach is at a dead end here, and can't be
resurrected.
<snip>
... . You'd be one of the first people
I'd expect to support furthering such understanding.

<snip>

And you would not have been someone I would have expected to champion
top-posting.


Yea, that's the thing about expectations. People will be who they are
regardless of our expectations.

Jun 7 '06 #17
JRS: In article <11**********************@c74g2000cwc.googlegroups .com>
, dated Tue, 6 Jun 2006 21:50:01 remote, seen in
news:comp.lang.javascript, gary <gb*****@gmail.com> posted :

Dr John Stockton wrote:

*** READ THE news:C.L.J FAQ ***

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 7 '06 #18
Thanks John, Yours seems to be the cloest answer yet. It seems strange I have to handle things like square brackets myself.
Why does that seem strange? Is it because your more familiar with VBs
replace function?

The replace method takes a RegExp so characters that have meaning in RegExp
will have to be escaped.
The same would be the case for all regex special characters, so in
reality its not useable to any extent without writing a function which
handles everything.


Add this in the top of your javascript:-

String.prototype.replaceText = function(search, replacement)
{
search = search.replace(this.rxSpecial,'\\$1')

var regexp = new RegExp(search, "g")

return this.replace(regexp, replacement)
}
String.prototype.rxSpecial =
/(\(|\)|\\|\^|\$|\||\?|\:|\[|\]|\.|\{|\}|\+|\*|\=|\!)/g

Now you can use this new method like this:-

"HELLO[WORLD]".replaceText("[WORLD]", " Kosmos")

Anthony.
Jun 8 '06 #19

Anthony Jones wrote:
Thanks John,

Yours seems to be the cloest answer yet.

It seems strange I have to handle things like square brackets myself.


Why does that seem strange? Is it because your more familiar with VBs
replace function?

The replace method takes a RegExp so characters that have meaning in RegExp
will have to be escaped.
The same would be the case for all regex special characters, so in
reality its not useable to any extent without writing a function which
handles everything.


Add this in the top of your javascript:-

String.prototype.replaceText = function(search, replacement)
{
search = search.replace(this.rxSpecial,'\\$1')

var regexp = new RegExp(search, "g")

return this.replace(regexp, replacement)
}
String.prototype.rxSpecial =
/(\(|\)|\\|\^|\$|\||\?|\:|\[|\]|\.|\{|\}|\+|\*|\=|\!)/g

Now you can use this new method like this:-

"HELLO[WORLD]".replaceText("[WORLD]", " Kosmos")

Anthony.


Thanks Anthony, that code was very useful.

Jun 8 '06 #20

"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Thanks John,
Yours seems to be the cloest answer yet.

It seems strange I have to handle things like square brackets myself.


Why does that seem strange? Is it because your more familiar with VBs
replace function?

The replace method takes a RegExp so characters that have meaning in

RegExp will have to be escaped.
The same would be the case for all regex special characters, so in
reality its not useable to any extent without writing a function which
handles everything.


Add this in the top of your javascript:-

String.prototype.replaceText = function(search, replacement)
{
search = search.replace(this.rxSpecial,'\\$1')

var regexp = new RegExp(search, "g")

return this.replace(regexp, replacement)
}
String.prototype.rxSpecial =
/(\(|\)|\\|\^|\$|\||\?|\:|\[|\]|\.|\{|\}|\+|\*|\=|\!)/g

Now you can use this new method like this:-

"HELLO[WORLD]".replaceText("[WORLD]", " Kosmos")

Anthony.

Another thought I've had is that if you want to preform the same replacement
repeatedly then rather than calling replaceText so this is better:-

String.prototype.replaceText = function(search, replacement)
{
return this.replace(this.getRegExpForText(search), replacement)
}
String.prototype.getRegExpForText = function(search)
{
search = search.replace(this.rxSpecial,'\\$1')
return new RegExp(search, "g")
}
String.prototype.rxSpecial =
/(\(|\)|\\|\^|\$|\||\?|\:|\[|\]|\.|\{|\}|\+|\*|\=|\!)/g
Rather then calling replaceText in a loop call getRegExpForText before the
loop, keep the returned RegExp object in a variable and use it with the
native replace function in the loop.


Jun 8 '06 #21
Csaba Gabor wrote:
Richard Cornford wrote:
Csaba Gabor wrote:
<snip>
I tried to modify the String object itself, similarly to the
below (by giving it a self value, to override any original
value), but I didn't get it working (yet?).


<example>
That seems a very extension dependent method of doing what ECMAScript
should be able to do by using a String object as the prototype for
another object:-


<example>
- Or using a closure to make the string value of the object private:-

...
Thanks for the nice examples. But is it not possible to modify the
String prototype directly? The below code that I tried works in FF,
but it fails in IE 6: changeStr works as expected, changing .self on


In the beating a dead horse category, I took another approach. Rather
than trying to modify the String prototype directly (on account of IE
wanting to do a "copy" when it saw the string object), I thought
perhaps I could redefine it. And anyway the structure should be
cleaner. Once again, it works in FF and fails (though not so badly) in
IE.

But the failure in IE is still quite bad. Everything is OK except the
..length property is uniformly 0. That is to say, IE's jscript
steadfastly refuses to let me affix a .length property to the revised
String object. It wants to reflect the underlying prototype's .length,
as far as I can tell.
oldString = String;
String = function(st) { this.set(st); }
String.prototype = oldString.prototype;
String.prototype.toString = function() { return this.value; }
String.prototype.valueOf = function() { return this.value; }
String.prototype.set = function(replacement, searchRE) {
if (arguments.length<2) this.value = oldString(replacement);
else this.value = this.replace(searchRE, replacement); }

function changeStr (oStr, newStr) { oStr.set(newStr, /.*/); }

var u = new String('yyy');
var t = new String(u);
alert ("old t: " + t + "\nlength: " + t.length);
changeStr(t, 'xxu xxz');
alert(
'string [xxu xxz] = "' + t+'"'+
'\nlength [7] = '+t.length+
'\nindex of u [2] = '+t.indexOf('u')+
'\nlast index of x [5] = '+t.lastIndexOf('x')+
'\nsubstring(4, -1) [xxu ] = "'+t.substring(4, -1)+'"'+
'\ncharAt(2) [u] = "'+t.charAt(2)+'"'+
'\ncharCodeAt(3) [32] = '+t.charCodeAt(3)+
'\nconcat(" ff", 4) [xxu xxz ff4] = '+t.concat(" ff", 4)+
'\nmatch("x") [x] = "'+t.match("x")+'"'+
'\nsearch("x") [0] = '+t.search("x")+
'\nslice(2, 5) [u x] = "'+t.slice(2, 5)+'"'+
'\nsplit("x") [,,u ,,z] = '+t.split("x")+
'\ntoUpperCase() [XXU XXZ] = "'+t.toUpperCase()+'"'
);
alert ("old u: " + u + "\nlength: " + u.length);

Jun 9 '06 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Brian | last post by:
I want to use regxp to check that a form input contains at least 1 non-space charcter. I'd like to only run this if the browser supports it. For DOM stuff, I'd use if (documentGetElementById) {}...
5
by: Michael Hiegemann | last post by:
Hello, I am unaware whether this is the right group to ask. Please point me to another forum if required. I would like to replace a Fortran function by one which is written in C. The function...
5
by: Hilary Cotter | last post by:
I'm trying to replace the characters in a pointer from an url string. Here is my code. // string has embedded '+', this code will not work. VOID PatchQuery(char *szQuery, char...
4
by: jgabbai | last post by:
Hi, What is the best way to white list a set of allowable characters using regex or replace? I understand it is safer to whitelist than to blacklist, but am not sure how to go about it. Many...
2
by: Evan | last post by:
Hey, I posted this yesterday, but no one had any ideas? C'mon now, I know this isn't that hard, i'm just a little new to javascript, and I can't quite figure this out. I searched and searched to...
5
by: xla76 | last post by:
Can anyone help me, I'm trying to replace any double quotes in a textbox with a different character. mystring = Replace(TextBox.Text , " , "*") I've tried chr(34) and """"" with no luck. ...
1
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
25
by: magix | last post by:
Hi, I have char* str1 = "d:\temp\data\test.txt" I want to replace all the "\" to be "\\", so that the string will have "d:\\temp\\data\\test.txt" Can you help ?
3
by: Ned White | last post by:
Hi All, To replace some substrings in a string value, i use Regex.Replace method mulptiple times like; strmemo = "new Data for user; Name:@@Name , Surname:@@Surname, Address:@@Address";...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.