473,465 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Replace escape characters driving me mad

3 New Member
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
3 4231
gits
5,390 Recognized Expert Moderator Expert
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
metamind
3 New Member
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
metamind
3 New Member
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

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

Similar topics

5
by: KathyB | last post by:
Hi, not sure this is the right group, but hoping someone may have experienced this. I'm passing html text as a parameter to a javascript. When it has an apostrophe in it, of course it does parse...
24
by: Wim Roffal | last post by:
Is there a possibility to do a string replace in javascript without regular experessions. It feels like using a hammer to crash an egg. Wim
14
by: Etu | last post by:
Hi, I have a string: string c = "'abc' \"cde\", 'mno' \"xyz\","; how can I use the c.Replace(???, ???) method to have this string: "'abc' "cde", 'mno' "xyz"," that is, all the...
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
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...
4
by: jpierson | last post by:
Hi, I'm having a few problems with the replace function for replacing characters in a textbox. "C:\" is the string i am tryin to remove ,with it a command I am sending does not work. ...
1
by: =?Utf-8?B?R3VoYW5hdGg=?= | last post by:
I have a string with some escape charaecters that need to be processed in our file Say for example the string might have something like following <escape V=".sp2" /> step 1: This has to be...
0
by: =?Utf-8?B?R3VoYW5hdGg=?= | last post by:
I have a string with some escape characters that need to be processed in our file Say for example the string might have something like following <escape V=".sp2" /> step 1: This has to be...
6
by: Gabriel | last post by:
Hello, I do this : s = Environment.CurrentDirectory; s = s.Replace("\\", @"\"); Environment.CurrentDirectiry return a path like this C:\\....\\....\\..... I'd like replace the \\ by \, but...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.