String manipulation

Hi, I am having problems with string manipulation. I downloaded questions for quiz app but they are not really good formatted. I tried to solve the problem of fragments of text like """ by trying to simply replace it. I upload a screenshot of my trial. Do you know how to solve it? Screen Shot 2021-12-19 at 21.53.25
Another problem is with getting rid of square brackets around my question. I tried to do it by just selecting the first item from list but the app inventor "told" me that it is not a list.

To sum up i want to get rid of these ugly fragments of text and square brackets around text. I tried to solve it for some time but all my ideas turned out to be wrong.

Show how you are getting the content for your global questions (where are they from, how do you get them?). This might be the source of your problems.

@szymekkart250 One next approach could be:

1 Like

Screen Shot 2021-12-19 at 23.00.04

what is global text here? the question as a whole?

@szymekkart250 it's only a general marker; put in your text the square brackets should be removed from.

1 Like

I prefer to work with lists as opposed to dictionaries, even though this may be a bit more long winded.

See the attached aia project which returns a flat list for each question (sets the incorrect answers as elements of the main list instead of being in a sub list). This does remove the keys, so you will need to note the order, which comes back alphabetically.

handleOpentdb.aia (4.0 KB)

You may not want to go down this route, but it does show how to handle the escaped html characters. I have replaced both with an apostrophe to maintain the list order of things.

2 Likes

Hello szymekkart250

Does your App have to download the questions from a web page? If it does have to, is that website yours? If it is yours, you can collect a CSV file instead of HTML. If you don't have to download you can store a CSV file in the App, or send me that file and I can convert it into a Blocks List.

I download this file from URL. A couple of replies above there is the process of downloading the json. Thanks for Your help!

I download this file from URL. A couple of replies above there is the process of downloading the json.

What I mean is - does the App only ever perform the download once, only use this data?

The idea is that I download the data once, when the user want to start a quiz game. Later I want to display this data on the screen. So yeah, somehow I can tell that it performs the download once, but there can be a second download when sbd want to play another game.

So it sounds as though you have control of the online data - so why not download a CSV file that has no formatting issues?

@ChrisWard How do I get a CSV file? Is it done by using the "Web.GotText" and processing the "responseContent"? I havn't worked with it so far. Thanks!

Is it your own website?

No, this was a general question following the discussion here I'm interested in.

So you can only get a CSV if the website owner makes one available.

1 Like

@ChrisWard Ah, thank you!

Can you direct the Web1 GotText responseContent to a temporary Text Box, copy it, send it to yourself via email and post it here as a text file? Or alternatively let us have the URL.

Here is a sample url

https://opentdb.com/api.php?amount=10&type=multiple

It will return different questions every time

1 Like