7 examples of 'javascript find in string' in JavaScript

Every line of 'javascript find in 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
1export function searchAndReplace(str, find, replace) {
2 return str.split(find).join(replace)
3}
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};
112function findAll(str: string, toFind: string): number[] {
113 var matches = [];
114 var i = str.indexOf(toFind);
115 while (i !== -1) {
116 matches.push(i);
117 i = str.indexOf(toFind, i + toFind.length);
118 }
119 return matches;
120};
16function findString(stringToSearch, uint8Array) {
17 const result = [];
18 const searchString = stringToSearch
19 .split('')
20 .map((char) => char.charCodeAt(0));
21
22 const maxIndex = uint8Array.length - stringToSearch.length;
23 let index = -1;
24 for (const char of uint8Array) {
25 index++;
26 if (index > maxIndex) {
27 return result;
28 }
29 if (char === searchString[0]) {
30 if (_findArray(searchString, index, uint8Array)) {
31 result.push(index);
32 if (result.length > MAX_ELEMENTS_TO_SEARCH) {
33 return result;
34 }
35 }
36 }
37 }
38 return result;
39}
28search (string, startPosition, callback) {
29 if (startPosition == null) { startPosition = 0 }
30 if (typeof startPosition === 'function') {
31 callback = startPosition
32 startPosition = 0
33 }
34
35 this.scanner.findNextMatch(string, startPosition, (error, match) => {
36 callback(error, this.captureIndicesForMatch(string, match))
37 })
38}
20function replaceAll (input, find, replace) {
21 let regex = new RegExp(find, 'g');
22 return input.toString().replace(regex, replace);
23};
174function find(pattern, backwards, regex) {
175 var s = new Search();
176
177 s.needle = pattern;
178 s.wrap = true;
179 s.caseSensitive = true;
180 s.regExp = regex;
181
182 if (backwards)
183 editor.findPrevious(s, false);
184 else
185 editor.findNext(s, false);
186
187 centerLine(getLine());
188}

Related snippets