mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 13:43:49 +01:00
25 lines
823 B
JavaScript
25 lines
823 B
JavaScript
//Netburner String helper functions
|
|
|
|
//Searches for every occurence of searchStr within str and returns an array of the indices of
|
|
//all these occurences
|
|
function getIndicesOf(searchStr, str, caseSensitive) {
|
|
var searchStrLen = searchStr.length;
|
|
if (searchStrLen == 0) {
|
|
return [];
|
|
}
|
|
var startIndex = 0, index, indices = [];
|
|
if (!caseSensitive) {
|
|
str = str.toLowerCase();
|
|
searchStr = searchStr.toLowerCase();
|
|
}
|
|
while ((index = str.indexOf(searchStr, startIndex)) > -1) {
|
|
indices.push(index);
|
|
startIndex = index + searchStrLen;
|
|
}
|
|
return indices;
|
|
}
|
|
|
|
//Replaces the character at an index with a new character
|
|
String.prototype.replaceAt=function(index, character) {
|
|
return this.substr(0, index) + character + this.substr(index+character.length);
|
|
} |