Read txt file online

Dears,


How can I read a txt file online and store the values into an array?


The user will type something like "SBKP", and the system go online, and look for SBPK on a text file similar to the following example:


A|02WA|CAWLEYS SOUTH PRAIRIE|47152325|-122094003|690

R|16|160|2650|0|0|0|47155952|-122094002|690|300|40

R|34|340|2650|0|0|0|47148682|-122094002|690|300|40


A|04**|STILLWATER CREEK|46958358|-119638819|1510

R|11|110|4100|0|0|0|46958358|-119638819|1510|300|40

R|29|290|4100|0|0|0|46958358|-119638819|1510|300|40


A|SBKP|WESTERN|46924986|-122553039|394

R|09|90|2845|0|0|0|46925831|-122556397|394|300|50

R|27|270|2845|0|0|0|46923697|-122547939|394|300|50


When SBKP found, the system will collect all information and store into an array.


How can I do it?


Thank you so much!

Replies

Where is your problem ?


Is it getting the file ?

Is it to find the string in text ?


When SBKP found, the system will collect all information and store into an array.

What information in your example ?


I would advise you to search a little by yourself, to formulate precisely what you want to get, that is the best way to learn.

This is not a question about a feature of the Swift language, so it’s posted in the wrong forum. Getting Started might be better.


And as Claude pointed out, the question is far too vague. You’re effectively asking “how do I build an entire client-server app infrastructure”? An analogy someone else on here used is that it’s like going on a forum for carpenters and asking “how do I build a house?” This is quite an ambitious project if you don’t yet know where to start.


The general steps are going to be something like

- build a database on a server to store your data (MySQL or similar)

- design a REST API that your app can use to query the database (usually PHP on the server, JSON on the wire)

- implement the API on both the client and server


But those steps are still too vague. You’re going to have to do some of it and come back with more specific questions once you get into it, I think. Anyway you can read up on “full text search” for an idea of how to do the database part. I use FTS for searching an on-device SQLite database and it works great. Might be ok over the network too but of course it’s going to be a lot slower, maybe too slow to search as the user types. You’d have to try it.