use a CR LF as a separator for tokenat?

Get help using Construct 3!

Post » Sat Dec 02, 2017 5:01 pm

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.
B
11
S
3
Posts: 62
Reputation: 813

Post » Sat Dec 02, 2017 5:33 pm

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:

Code: Select all
CSVstring = replace(InputString, newline, ",")


Then you can parse through CSVstring using tokenat and "," as the separator.
A big fan of JavaScript.
B
76
S
20
G
76
Posts: 2,284
Reputation: 47,552

Post » Sat Dec 02, 2017 5:43 pm

You can use newline as the separator.
ImageImageImage
B
71
S
22
G
257
Posts: 3,790
Reputation: 142,696

Post » Sat Dec 02, 2017 6:19 pm

Colludium wrote: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:

Code: Select all
CSVstring = replace(InputString, newline, ",")


Then you can parse through CSVstring using tokenat and "," as the separator.


That's what I was trying to avoid. But thanks anyway :)
B
11
S
3
Posts: 62
Reputation: 813

Post » Sat Dec 02, 2017 6:21 pm

blackhornet wrote:You can use newline as the separator.


Thanks! It works :)
B
11
S
3
Posts: 62
Reputation: 813


Return to How do I...?

Who is online

Users browsing this forum: NN81 and 1 guest