tokenat seems to be putting a carriage return at the start?

0 favourites
  • 9 posts
  • I'm splitting a .txt file into an array using tokenat.

    However, when I go to check if part of it equals, for example "<NP>" it wont show it as being so.

    Eventually I've figured a carriage return is being added to the front of the string when it is split.

    Why does this happen and can I make it go stop now??

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Are you sure the carriage returns are at fault? I haven't been able to replicate the issue, even using files with Windows style line endings. It might help if you post your capx and txt files.

  • Are you taking into account that it is zero based?

  • Okay, tokenat isn't adding the carriage returns, they were just in my text file.

    When I made my text file just one long line, the project worked! But it's a pain (though not impossible) to work on an instructions file that's one massive long line.

    Is there any way to remove carriage returns from a text? I've looked before and construct doesn't seem to have anything equivalent to 'chr' that other programs do. So I don't know how to point at carriage returns to make construct remove them (not even sure of the removal command either)

  • Okay, I have a work around by just trimming the first character of every line (that's where the carriage return ends up after tokenat takes it's sample). I have to have one carriage return at the start of the text document for this to not erase the first character of the first line. And I have to add the '<END>---' at the end manually, because putting it in manually adds a carriage return and I have no other way of doing that currently. Before I had the program add that.

    Still would like a way of removing all carriage returns, if it's out there.

  • You should be able to use tokenat with the CR (newline), and then again for the data you want.

  • How do I get tokenat to aim itself at a carriage return? Something like tokenat(string,X,newline)?

    Besides, what would it do for me in changing the original data?

  • Yes, use 'newline'. This gets you each line, then you can break that line into tokens with your original separator.

  • Okay, I'll try that next time. Thanks, blackhornet

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