2016-12-19 19:20:19 +01:00
|
|
|
//Netburner String helper functions
|
2016-12-15 23:22:42 +01:00
|
|
|
|
|
|
|
//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;
|
2016-12-21 17:33:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//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);
|
2016-12-15 23:22:42 +01:00
|
|
|
}
|