Our link is generated in this format site.com/&message=Test+ example+text
I use JS. So, how to do that when we parse the data from the link, how do we print the text so that instead of "+" there are spaces?
Our link is generated in this format site.com/&message=Test+ example+text
I use JS. So, how to do that when we parse the data from the link, how do we print the text so that instead of "+" there are spaces?
You can regular, after creating your function:
String.prototype.replaceAll = function(search, replacement) { return this.replace(new RegExp(escapeRegExp(search), 'g'), replacement); }; // нужно для экранирования специальных символов перед срезом function escapeRegExp(str) { return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& значит: все совпадения } then:
"Test+пример+текста".replaceAll('+', ' ')
Or using split and join
split splits a String object into an array of strings by dividing the string with the specified substring. Syntax: str.split([separator[, limit]]) . Where separator is an optional parameter. Specifies the characters used as a delimiter within a string. The separator parameter can be either a string or a regular expression.
join - joins all elements of the array into a string. Syntax: str = arr.join([separator = ',']) , where separator is an optional parameter. The string that separates the elements of the array is determined. The delimiter is cast to the string if necessary. If omitted, the elements of the array are separated by a comma.
String.prototype.replaceAll = function(search, replacement) { var target = this; return target.split(search).join(replacement); }; Similarly: "Test+пример+текста".replaceAll('+', ' ')
Source: https://ru.stackoverflow.com/questions/528486/
All Articles