Copy link to clipboard
Copied
Let's say someone copies the folowing list and pastes it into a Javascript prompt box:
302304
305678
245675
How do I manipulate the string so it reads:
302304 305678 245675
In other words, how do I replace the manual line breaks in a string with spaces?
Thanks!
This is the cleaner method you were looking for:
/[\n\r]/
In this situation, even a simple \s would work, but that might not be what the OP was looking for...
Harbs
Copy link to clipboard
Copied
Im still not very good with these reg exp but this would work although Im sure I missed a cleaner way…
var st = "302304\n305678\r245675"; $.write(st); $.writeln(''); var ns = st.replace(/(\r|\n)/g,' '); $.write(ns);
Copy link to clipboard
Copied
This is the cleaner method you were looking for:
/[\n\r]/
In this situation, even a simple \s would work, but that might not be what the OP was looking for...
Harbs
Copy link to clipboard
Copied
Thanks!
the final result works:
stringName = stringName.replace(/(\r|\n|\s)/g,' ');
Copy link to clipboard
Copied
\r and \n are both \s characters.
This is functionally equivalent to what you have...
stringName = stringName.replace(/\s/g,' ');
I highly recommend browsing this website (lots of useful info there):
http://www.regular-expressions.info/
Harbs
Find more inspiration, events, and resources on the new Adobe Community
Explore Now