Announcement

Collapse
No announcement yet.

String tokenizer?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • String tokenizer?

    Anybody got a routine to tokenize a string on a separator character and return an array of string tokens? TIA

  • #2
    Try this out... it should do the trick.

    PHP Code:
    function Tokenize(vString) {
        
        var 
    aString = new Array(vString.length);
        for (
    i=0vString.lengthi++) {
            
    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

    Comment


    • #3
      Thanks for the routine.

      I also found the string split function.

      Great support!

      Comment


      • #4
        Just for the thread's reference... here's the split function for the String object.
        Regards,
        Jay F.
        Product Manager
        _____________________________________
        Have a suggestion to improve our products?
        Click Support --> Request a Feature in eSignal 11

        Comment


        • #5
          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


          • #6
            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 (!= 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<40i++){dd[i] =parseFloat(dd[i]);}//converts text to numbers
                
            return dd;

            If you want to mix numbers and text in the same file, here is what I do (from a separate routine)...
            PHP Code:
                for (i=0;i<100i++){
                    
            debugPrintln("dd["+i+"] = "+dd[i]);
                    if (
            == || == 44){newArray[i] = dd[i];i++;}//these are the two text fields
                    
            newArray[i] = parseFloat(dd[i]); 
            note that array values 6 and 44 are text, so I do not parse.

            Regards,

            Comment

            Working...
            X