Anybody got a routine to tokenize a string on a separator character and return an array of string tokens? TIA
Announcement
Collapse
No announcement yet.
String tokenizer?
Collapse
X
-
Try this out... it should do the trick.
PHP Code:function Tokenize(vString) {
var aString = new Array(vString.length);
for (i=0; i < vString.length; i++) {
aString[i] = vString.charAt(i);
}
return aString;
}
Regards,
Jay F.
Product Manager
_____________________________________
Have a suggestion to improve our products?
Click Support --> Request a Feature in eSignal 11
-
-
Just to make sure anyone doing a search gets a complete reply...
This code fragment shows how to split an array of strings that is delineated by comma's. You can specify any delineator you want by changing the "," in MyLine.split().
var vMyLine = "This,is,a,test";
var vTest = vMyLine.split(",")
// vTest[0] should be: This
// vTest[1] should be: is
// vTest[2] should be: a
// etc
var i;
for (i=0; i < vTest.length; i++){ // verify
debugPrintln("vTest[" + i + "] = " + vTest[i]);
}Garth
Comment
-
sample efs, obtaining file values
Here is a code snippet that I have which obtain file values. It is set up to parse the text values to numbers, but that step can be taken out. This is just an excerpt from some of my code and this efs does not run, although it would not take much to make it work.
PHP Code:var ff =0;
function preMain() {
ff = getDef2();//gets flag variablesinitializes flags
function main(){
}
function getDef2 (){//flag data
var fl2 = new File("Buy Code Flags.txt");
if (fl2.exists){
fl2.open("rt+");
var d=fl2.readln();
fl2.close();
tTime = nTime();//tTime [0] = milliseconds, [1] = h:m:s, [2] = MM-DD-YYYY, [3] = h, [4] = m, [5] = s, [6] = Total s.
if (d != null ){var dd=d.split(",");}
else{
var dd = Initialize_1X_Array(40);//sets all of them to zero
return;
}
}
else {var dd = Initialize_1X_Array(40);}//if file does not exist, sets all of them to zero
var i;
for (i=0;i<40; i++){dd[i] =parseFloat(dd[i]);}//converts text to numbers
return dd;
}
PHP Code:for (i=0;i<100; i++){
debugPrintln("dd["+i+"] = "+dd[i]);
if (i == 6 || i == 44){newArray[i] = dd[i];i++;}//these are the two text fields
newArray[i] = parseFloat(dd[i]);
Regards,
Comment
Comment