Help | find index of two ""

Hey everyone,
I have to find index of two "" and take to another variable what is between for example:

String Text = "42["Hello World"]"

I would like to cut everything and just leave the Hello World:

Text = "Hello World"

Can you please give me an example of code of how to do it?
Thanks everyone!

To find a character within a string:

int firstQuote = Text.indexOf('"'); -- Thats a sinqle Quote ' followed by a double Quote " and another single Quote '

To find the last occurrence of a character within a string:

int lastQuote = Text.lastIndexOf('"');

To extract a substring:

Text = Text.substring(firstQuote, lastQuote);

1 Like

WisterDesigns:

String Text = "42["Hello World"]"

Note: You have to 'escape' quote characters inside strings to get it to compile:String Text = "42[\"Hello World\"]"

Didn't understand, Can you please explain it better?

To find the last occurrence of a character within a string:

int lastQuote = Text.lastIndexOf('"');

If you want the location of the first double quote, and then the location of next double quote (instead of the last double quote), the indexOf() function takes an optional second argument, defining where to start the search from. Starting the search from the position after a double quote will find the next double quote.