read string data from csv- karel

  • hello friends


    i was trying to make a program for reading data from csv..
    my data will be like LWP15452,145 i need to read LWP15452 and 145 seperate.. in present i can able to read the entire line ..
    pls help



    thanks
    vipin

    Thanks regards<br />Vipin..

  • Hello,


    is the number of characters always the same? If so, you can just use the built-in function SUB_STR(source_string , start, len) that return a substring of source_string starting from start character and takes up to len characters


    An example would be:

    Code
    first_part : STRING[8]
    second_part : STRING[3]
    
    
    first_part = SUB_STR(full_line, 1, 8)
    second_part = SUB_STR(full_line, 10, 3)

  • Hello,


    is the number of characters always the same? If so, you can just use the built-in function SUB_STR(source_string , start, len) that return a substring of source_string starting from start character and takes up to len characters


    An example would be:

    Code
    first_part : STRING[8]
    second_part : STRING[3]
    
    
    first_part = SUB_STR(full_line, 1, 8)
    second_part = SUB_STR(full_line, 10, 3)


    hi...
    thanks for that, but number of characters is not same in my case...

    Thanks regards<br />Vipin..

  • The standard way would be to use regular expression, but as far as I know there isn't support in Karel.
    A workaround here would be to use some IF clauses and the built-in function STR_LEN to identify how your string is structured or maybe check where the ',' is, that depends on the format of your string.
    Once you have to correct lengths you can use SUB_STR as I shown

  • This will probably do


  • This will probably do


    Hi..


    great this is working.... thanks

    Thanks regards<br />Vipin..

Advertising from our partners