When I want to replace "abc" by "xyz" i use the following command:
str.split("abc").join("xyz");
But what if I have the following string "This is just a test string" and would like to replace only the second whitespace by "\n".
When I want to replace "abc" by "xyz" i use the following command:
str.split("abc").join("xyz");
But what if I have the following string "This is just a test string" and would like to replace only the second whitespace by "\n".
To improve on @fsbmain's answer, n-th occurence can be replaced in using '/(( [^ ]+){3}) /' (http://regexr.com?33nm5):
var str:String = ("This is just a test string").replace(/(( [^ ]+){3}) /, "$1\n");
trace(str);
The output would be:
This is just a test string
You can use this regExp:
var str:String = ("This is just a test string").replace(/(.[^ ]+ .[^ ]+) /, "$1\n");
trace(str);
output:
This is just a test string