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

Just started using Construct 2? Post your questions here

Post » Mon Feb 22, 2016 3:50 am

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??
B
52
S
15
G
4
Posts: 191
Reputation: 5,612

Post » Mon Feb 22, 2016 4:59 am

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.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Mon Feb 22, 2016 5:30 am

Are you taking into account that it is zero based?
Image ImageImage
B
172
S
50
G
183
Posts: 8,440
Reputation: 115,599

Post » Mon Feb 22, 2016 5:40 am

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)
B
52
S
15
G
4
Posts: 191
Reputation: 5,612

Post » Mon Feb 22, 2016 6:02 am

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.
B
52
S
15
G
4
Posts: 191
Reputation: 5,612

Post » Mon Feb 22, 2016 6:27 am

You should be able to use tokenat with the CR (newline), and then again for the data you want.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Mon Feb 22, 2016 9:09 am

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?
B
52
S
15
G
4
Posts: 191
Reputation: 5,612

Post » Mon Feb 22, 2016 2:54 pm

Yes, use 'newline'. This gets you each line, then you can break that line into tokens with your original separator.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Tue Feb 23, 2016 3:55 am

Okay, I'll try that next time. Thanks, blackhornet
B
52
S
15
G
4
Posts: 191
Reputation: 5,612


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests