10 examples of 'jquery replace string' in JavaScript

Every line of 'jquery replace string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
62function replaceString(pString,pSearch,pReplace)
63// replaces in the string "pString" multiple substrings "pSearch" by "pReplace"
64{
65 //alert("cstring.js - replaceString() "+pString);
66 if (!pString) {
67 alert("replaceString()-Call - pString not defined!");
68 } else if (pString != '') {
69 {
70 //alert("cstring.js - replaceString() "+pString);
71 var vHelpString = '';
72 var vN = pString.indexOf(pSearch);
73 var vReturnString = '';
74 while (vN >= 0)
75 {
76 if (vN > 0)
77 vReturnString += pString.substring(0, vN);
78 vReturnString += pReplace;
79 if (vN + pSearch.length < pString.length) {
80 pString = pString.substring(vN+pSearch.length, pString.length);
81 } else {
82 pString = ''
83 }
84 vN = pString.indexOf(pSearch);
85 };
86 };
87 return vReturnString + pString;
88 }
89
90};
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

102function replaceString(s, x) {
103 return x.replace(new RegExp("\\\\" + s, "g"), "\\$&").replace(/\n/g, "$&" + spaces(indent) + " ")
104}
92export function replace(str, regexp){
93
94 for(let i = 0, len = regexp.length; i < len; i += 2){
95
96 str = str.replace(regexp[i], regexp[i + 1]);
97
98 if(!str){
99
100 break;
101 }
102 }
103
104 return str;
105}
43function replaceAll(str) {
44 if (str != null){
45 str = str.replace(/\n\t/ig, "<br />");
46 }
47 return str;
48}
103function replaceAll(string, find, replace){
104 return string.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
105}
507export function replaceAll(str, find, replace) {
508 return str.replace(new RegExp(find, "g"), replace);
509}
172function replaceByString(re, replacement, input) {
173 return input.replace(re, replacement);
174}
1export function searchAndReplace(str, find, replace) {
2 return str.split(find).join(replace)
3}
14export function replace (text: string, start: number, len: number, str: string): string {
15 if (!text)
16 return str;
17 return [text.slice(0, start), str, text.slice(start + len)].join('');
18}
88replace: function replace(aString) {
89 if (!aString) return aString;
90 this.substitutions.forEach(function(element) { aString = element.replace(aString); });
91 return aString;
92},

Related snippets