JavaScript – Replace all commas in a string [duplicate]

This question already has answers here: How to replace all occurrences of a string in JavaScript (79 answers) Closed 7 years ago. I have a string with multiple commas, and the string replace method will only change the first one: var mystring = “this,is,a,test” mystring.replace(“,”,”newchar”, -1) Result: “thisnewcharis,a,test” The documentation indicates that the default replaces … Read more

Substitute multiple whitespace with single whitespace in Python [duplicate]

This question already has answers here: Is there a simple way to remove multiple spaces in a string? (24 answers) Closed 7 years ago. I have this string: mystring = ‘Here is some text I wrote ‘ How can I substitute the double, triple (…) whitespace chracters with a single space, so that I get: … Read more