Syntax : customSplit(strValue, separator, strArrayName)
strValue is the string to be splited with separator as the delimeter. After spliting, array of strings are stored in new "Array" object, strArrayName. function customSplit(strvalue, separator, arrayName) {
var n = 0;
if (separator.length != 0) {
while (strvalue.indexOf(separator) != -1) {
eval("arr"+n+" = strvalue.substring(0, strvalue.indexOf(separator));" );
strvalue = strvalue.substring(strvalue.indexOf(separator)+separator.length,
strvalue.length+1);
n++;
}
eval("arr" + n + " = strvalue;" );
arraySize = n+1;
}
else {
for (var x = 0; x < strvalue.length; x++) {
eval("arr"+n+" = \"" + strvalue.substring(x, x+1) + "\";" );
n++;
}
arraySize = n;
}
eval(arrayName + " = new makeArray(arraySize);" );
for (var i = 0; i < arraySize; i++)
eval(arrayName + "[" + i + "] = arr" + i + ";" );
return arraySize;
}
Examples
var strvalue = "abc##123##zzz##$$$";
var returnArraySize = customSplit(strvalue, "##", "NewArray" );
The above will create the following:
NewArray[0] has value "abc"
NewArray[1] has value "123"
NewArray[2] has value "zzz"
NewArray[3] has value "$$$"
returnArraySize has value "4" |