Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex: replace all spaces with comma

im new with regexp, so can i ask for some assistance

Using string.replace function what code that can replace spaces with comma

Input:The quick brown fox jumps over the lazy dog. Output:The,quick,brown,fox,jumps,over,the,lazy dog.

Thanks

like image 345
Treby Avatar asked Mar 24 '10 01:03

Treby


1 Answers

Like this:

str = str.replace(/ /g, ',');

Here's a better one which will replace all strings of whitespace:

str = str.replace(/\s+/g, ',');
like image 79
SLaks Avatar answered Oct 10 '22 03:10

SLaks