Solved

How to replace with single quote ?

Posted on 2011-03-17
5
499 Views
Last Modified: 2012-05-11
The following expression replace a
forward slash with two single quotes

i want only to one single quote


item_name.replace(/\\/g,"\'");
0
Comment
Question by:PeteEngineer
5 Comments
 
LVL 3

Accepted Solution

by:
CombatGold1 earned 100 total points
Comment Utility
Instead of \' see if specifying the single-quote's hexadecimal reference works, which would be \0x27, or the octal reference \047.
0
 
LVL 16

Assisted Solution

by:sjklein42
sjklein42 earned 100 total points
Comment Utility
Your code seems to work fine:

(The code actually replaces backslashes \ , not forward slashes / .  Is that what you meant to say?)

<script>
var item_name = 'abc\\def'
alert(item_name)
item_name = item_name.replace(/\\/g,"\'");
alert(item_name)
</script>

Open in new window

0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 100 total points
Comment Utility
Perhaps you mean you want to replace a series of one-or-more slashes with just one single quote?
item_name.replace(/\\+/g,"\'");

Open in new window

0
 
LVL 3

Assisted Solution

by:grouper15
grouper15 earned 100 total points
Comment Utility
can you send the value of item_name you are having problem with
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 100 total points
Comment Utility
No need to escape the simple quote inside the double quote
item_name.replace(/\\/g,"'");

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now