question

Mallikarjun Reddy avatar image
0 Likes"
Mallikarjun Reddy asked Ben Wilson answered

How to import data from text files?.

I have a text file with multiple rows and columns and I have to read this data. If I am using filereadline(), I am getting text for particular row with concatenated texts from all columns. How to get the column data seperately?

FlexSim 17.0.0
import
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Sam Stubbs avatar image
1 Like"
Sam Stubbs answered Sam Stubbs edited

IF you have rows and columns you should probably import that data into an Excel format, then FlexSim can import that data as a table. Plain text files do not distinguish between rows and columns, so neither will FlexSim's file reading commands.

I suppose, if you need to have it as a text file, perhaps you could use some character or something delineate between column in the text lines. So that when you read the file line, you can add logic that will parse out data based on that delineating character. Using string commands such as stringsearch to find those delineating characters and break that string up.

That seems like it could be very complicated though, so again, if you need to read data like a table, I'd recommend importing that data as an excel spreadsheet, or storing it in a database that can be connected to.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image
1 Like"
Ben Wilson answered

If you are reading a text file, perhaps in a comma separated value (.csv) format, then you should familiarize yourself with the stringtoken() command.

That is probably how you'll parse the line of text you get from filereadline().

If your data file is in JSON format, you should check out this post.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.