Searching in a Text Data File

Hi, can someone help me perform two types of searches in a text file? Thanks.

I have a data file with 6 columns and several rows of data, and I want to perform some searches.
In the file, the line starts with - and the fields are separated by $
-Field1$Field2$Field3$Field4$Field5$Field6

First Search
The user enters a search term, and pressing the button searches for the word in Field1.
As a result, I want to display:
Field1 Value
Field2 Value
Field3 Value
Field4 Value
Field5 Image
Field6 Image (if present)

Second Search
The user enters a search term in the first and second boxes. When the button is pressed, the word from the first box is searched for in Field3 AND the word from the second box is searched for in Field4.
As a result, I want to display Field1 of all results:
Field1 Value
Field1 Value
Field1 Value

Example text file
-Pippo$Text Text Text Text $Circle$Red$pippo1.jpg$
-Pluto$Text1 Text1 Text1 Text1 $Circle$Green$pluto1.jpg$pluto2.jpg
-Paperino$Text2 Text2 Text2 Text2 $Square$Green$paperino1.jpg$
-Gastone$Text3 Text3 Text3 Text3 $Square$Red$gastone1.jpg$gastone2.jpg

esempio1

Why did you choose this format, instead of a straightforward comma separated csv ?

I can convert it to CSV format. But if there's text with commas in Field2, can I put the text between ""? For example, "Text,Text Text"?

Yes

Alternatively

image

(assumes you will never need a dollar sign in your values :slight_smile: )

image

How to load such a Dollar Separated (dsv?) table

(draggable)


https://ai2.appinventor.mit.edu/reference/concepts/pholo.html

1 Like

Hi, is there an example or tutorial (in Italian or English) for at least one of the two searches with results displayed? Thanks.

Please explain a bit more about your use case
How often does the text file change? Does it even change? Where does it come from? How large is it? Number of rows?

I'm asking, because usually you use a database for efficient searching... This could be for example the local sqlite database.You only have to import the data and then you could use the power of sql to do your search

Select * from myTable where Field1= Textbox1.Text

Select Field1 from myTable where Field1 = Textbox1.Text and Field4 = Textbox2 Text

To access the sqlite database you need an extension. There is my paid sqlite extension App Inventor Extensions: SQlite | Pura Vida Apps available, which is based on the KISS principle (keep it simple stupid). There are also other free sqlite extensions available.

Taifun

The two text files are immutable.
The first search is for my glossary of about 200 rows.
The second search is to identify objects with some particular characteristics. The file has about 60 rows.
I have a MySQL database (5 databases) that I use with PHP on my website.
I just discovered MIT APP Inventor 2 and am trying to learn it.

Ok, so what about querying your MySQL database from your app?

Taifun