By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

Replace escape characters driving me mad

P: 3
I have a string called "s" which contains "problems once you\x19ve secured the job!)."

I am trying to replace the \x19 character with "ww" in this case but

s.replace(/\x19/g, 'ww')

is just returning exactly the same thing. What am I doing wrong. This is driving me mad.

Many thanks.

Transcript below:

$[3] = [string] "problems once you\x19ve secured the job!)."
0002: s.replace(/\x19/g, 'ww')
$[4] = [string] "problems once you\x19ve secured the job!)."
Oct 22 '07 #1
Share this Question
Share on Google+
3 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

have you tried something like the following ... that should work:

Expand|Select|Wrap|Line Numbers
  1. var s = "problems once you\x19ve secured the job!"
  2. s = s.replace(/\x19/g, 'ww');
  3. alert(s);
  4.  
kind regards
Oct 22 '07 #2

P: 3
Hi,

Thanks for that. The wierd thing is that the escaped character does not seem to be behaving properly. The string "s" is pasted into a textarea. The original looks like this"impressions counting "you have".

I am looking at the string in a console (venkman in firefox). When I get it to print s it looks like this:

"impressions counting \x13 \"you have"

if I do:

s.indexOf('c')

I get:

[integer] 12

Which is what you would expect. But when I do:

s.indexOf('\x13')

I get:

[integer] -1

Suggesting that '\x13' is not in the string at all.

I have done all sorts but I still can't seem to locate the escaped character in the string. This is wierd since if I set up a string var v = "impressions counting \x13 \"you have" then I can see the character fine. I have included a transcript of what I have been doing at the end of this post after the ===== . (0001: is my prompt, lines starting $ are the returned values.

Wierd indeed!

Any ideas welcome

Regards


======================================
0001: s
$[1] = [string] "impressions counting \x13 \"you have"
0001: t = s.split(' ')
$[2] = [Array] [class: Array] {6}
0001: t[2]
$[3] = [string] "\x13"
0001: t[2] * 1
$[4] = [double] NaN
0001: t[2].length
$[5] = [integer] 1
0001: t[2].toString(16)
$[8] = [string] "\x13"
0001: var u = '\x13';
$[9] = [void] void
0001: u.length
$[10] = [integer] 1
0001: s.indexOf(u)
$[11] = [integer] -1
0001: s
$[12] = [string] "impressions counting \x13 \"you have"
0001: s.indexOf('c')
$[13] = [integer] 12
0001: s.indexOf('\x13')
$[14] = [integer] -1
0001: s.indexOf(u)
$[15] = [integer] -1
0001: var v = "impressions counting \x13 \"you have"
$[16] = [void] void
0001: v.indexOf('\x13')
$[17] = [integer] 21
0001: u == t[2]
$[18] = [boolean] false
Oct 23 '07 #3

P: 3
just tried escaping them. They are different (t[2] is the \x13 from the s while u has been set to \x13 in the code:

0001: escape(t[2])
$[21] = [string] "%u2013"
0001: escape(u)
$[22] = [string] "%13"
Oct 23 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.