Announcement

Collapse
No announcement yet.

How do you manipulate strings?

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

  • How do you manipulate strings?

    I am reading a file in my program. The file contains the date, Open, High, Low, and Close, all of them seperated by a comma. When I use f.readln() it reads the entire line of data. Once I get this data how can I break it into the areas I need (specifically the data under Close)? (Tried using f.read() and did not get any luck that way either.)

    In Visual Basic they have right$(), left$(), mid$() so you can easily manipulate the string to get the numbers you need. But I can't find anything like that in EFS. Can anyone point me in the right direction please.

    Jack

  • #2
    Re: How do you manipulate strings?

    Hi Jack,

    Here is a demo efs that opens a file, reads each line, converts each line to an array, then converts each string to a number, then returns a data array.

    Hope this helps.
    Steve

    PHP Code:
    //~ save this in the FormulaOutput folder in this location 'want2\myFile.txt'
    //~ 1,1,1,1,1,1
    //~ 2,2,2,2,2,2
    //~ 3,3,3,3,3,3
    //~ 4,4,4,4,4,4

    //~ Global Variables
    var bInit,filename,fileData;
    bInit=false;
    filename="want2\\myFile.txt";
    fileData=null;

    function 
    preMain() {
     
    setPriceStudy(true);
     
    setStudyTitle("fileData");
     
    setShowTitleParameters(false);
    }

    //~ Main processing function
    function main() {
     if (!
    bInit) {
      
    fileData=loadFile(filename);//~ loading file data
      
    debugPrintln("23: fileData = "+fileData);
      
    bInit=true;
     }
    }

    function 
    loadFile(tmp){
     var 
    x,data,fileObj,a;
     
    data=null;
     
    x=0;
     
    fileObj = new File(tmp);
     if(
    fileObj.exists()){
      
    data=[];
      
    fileObj.open("at+");
      while(!
    fileObj.eof()) {
       
    afileObj.readln();
       if(
    != null && a.indexOf(",")>){//~  prevents from reading lines which are null or with no comma
        
    a=a.split(",");
        var 
    n=a.length;
        while(
    n--){
         
    a[n]=+a[n];//~ [url]http://jibbering.com/faq/notes/type-conversion/[/url]
        
    }
        
    data[x++]=a;
       }
      }
     }
     
    fileObj.close();
     return 
    data;
     return 
    data;
    }
    //~ sample debugPrintln output
    //~ 23: fileData = 1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4 
    Originally posted by WantToLearn
    I am reading a file in my program. The file contains the date, Open, High, Low, and Close, all of them seperated by a comma. When I use f.readln() it reads the entire line of data. Once I get this data how can I break it into the areas I need (specifically the data under Close)? (Tried using f.read() and did not get any luck that way either.)

    In Visual Basic they have right$(), left$(), mid$() so you can easily manipulate the string to get the numbers you need. But I can't find anything like that in EFS. Can anyone point me in the right direction please.

    Jack

    Comment


    • #3
      After playing with it trying to understand how it all works I got it to work the way it should. Your example was very helpful and I appreciate you taking the time to help out.

      Thanks Steve,
      Jack

      Comment


      • #4
        Hi Jack,

        Your most welcome, good to hear it helped you code a solution.

        Steve

        Originally posted by WantToLearn
        After playing with it trying to understand how it all works I got it to work the way it should. Your example was very helpful and I appreciate you taking the time to help out.

        Thanks Steve,
        Jack

        Comment

        Working...
        X