Get data between single quotes Android

When you have string like "Chintan Rathod '[email protected]' place 'ahmedabad'" and you want to fetch out string which are between single quotes ('), then following code will do this thing.

Code
------

int second_index = 0;

int first_index = 0;

String str = "Chintan Rathod '[email protected]' place 'ahmedabad'";

while (true) {
       if (second_index == 0)
            first_index = str.indexOf("'", second_index);
       else
            first_index = str.indexOf("'", second_index + 1);
           
       if (first_index == -1)
            break;
           
       second_index = str.indexOf("'", first_index + 1);
           
       if (second_index == -1)
            break;

       String temp = str.substring(first_index + 1, second_index);
       Log.d("TAG",temp);
}

Output
--------

06-25 17:39:56.079: [email protected]
06-25 17:39:56.079: ahmedabad

Ebook Download
View all
Learn
View all