0

Given the string like this

This is a string - ["Testing", [["Test" , 0]] , [["TTest2",0,[23]]]

How can i extract all string in the double quote "" into an array like Testing, Test, TTest2 ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • If the whole thing is a string, then you need to do some complex string manipulation. but if it is a part of json, then you can format it into an array and work with that. – GeneCode Nov 09 '17 at 05:43
  • how can i do the string manipulation ? –  Nov 09 '17 at 05:45
  • many ways to do it. using regex is one of it. See here: https://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks – GeneCode Nov 09 '17 at 05:47

1 Answers1

0

You'll have to loop through your external array, and for each element check:

  • If it's a string, add it to an array.
  • If it's an array, then go into it and repeat the same process
  • If it's any other type, move forward.

This can (should) be done recursively.

Kunal Shah
  • 1,071
  • 9
  • 24
  • What do mean by loop through external array ? The above following is a string. –  Nov 09 '17 at 05:44
  • Before you made an edit, no one could've ever guessed that it's a string. – Kunal Shah Nov 09 '17 at 05:45
  • 1
    Kunal Shah, I am sorry about that. –  Nov 09 '17 at 05:47
  • This can be solved using a stack. Pop each '[' into a stack and keep pushing in elements till you reach an " (open quotes). The keep track of what comes after until you reach a " (close quotes). Ignore the elements, if you get an alphanumeric character without a preceeding open quote. Continue this until you reach the end of the string. – Kunal Shah Nov 09 '17 at 05:48
  • Can you add your sample code into the answer ? I kinda get what you mean but i have no idea how to write the code. –  Nov 09 '17 at 05:54