use a CR LF as a separator for tokenat?

0 favourites
  • 5 posts
  • I'm trying to parse a file list such as:

    apple

    pear

    banana

    I know this would be easy to do with a comma, but this is how all the files I'm using are constructed (and there's over 50 files).

    I tried using the hex codes for CR & LF (0D 0A 2 times) but I got an error: tokenat(file,n,0D0A0D0A)

    tokenat(src, index, separator)

    Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This is easy if you replace the CRs with commas or another separator, for the tokenat to work. Lets say your imported data is in a string variable "InputString". First you have to replace the CR values with commas and load that into a second variable "CSVstring".

    Use the System replace like this:

    CSVstring = replace(InputString, newline, ",")[/code:2wbsh3e8]
    
    Then you can parse through CSVstring using tokenat and "," as the separator.
  • You can use newline as the separator.

  • This is easy if you replace the CRs with commas or another separator, for the tokenat to work. Lets say your imported data is in a string variable "InputString". First you have to replace the CR values with commas and load that into a second variable "CSVstring".

    Use the System replace like this:

    CSVstring = replace(InputString, newline, ",")[/code:1ga6e982]
    
    Then you can parse through CSVstring using tokenat and "," as the separator.
    

    That's what I was trying to avoid. But thanks anyway

  • You can use newline as the separator.

    Thanks! It works

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)