Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How to replace comma by double quote in javascript? For example: "c,C#,JavaScript" should be like "C","C#","JavaScript"
split
a,b,c
a","b","c
str = '"c,C#,JavaScript"'; str = str.split(',').join('","');
That would result in "c","C#","JavaScript"
"c","C#","JavaScript"
Add a comment
var original = '"c,C#,JavaScript"'; var quoted = original.replace(/,/g, '","'); // "c","C#","JavaScript"
Just to toss it in there, you could also .split() and .join(), like this:
.split()
.join()
var oldString = '"c,C#,JavaScript"'; var newString = oldString.split(',').join('","');
You can test it here.
You can do this:
str = "c,C#,JavaScript"; str = str.replace(/,/g, '"');
Result:
c"C#"JavaScript
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
split...a,b,ctoa","b","c?