Parsing String


I have this String:

+CWLAP:(0,"Oi WiFi Fon",-53,"52:84:b0:9b:93:a4",6) +CWLAP:(3,"Time Capsule New",-53,"d0:84:b0:9b:93:a7",6)

And I need to parse this information from string:

Oi WiFi Fon Time Capsule New

Right now, what I can do is parse the first one, but I'm stuck in how to parse the next one. Could some one help me parse these information, and also if I have more data like:

+CWLAP:(0,"Oi WiFi Fon",-53,"52:84:b0:9b:93:a4",6) +CWLAP:(3,"Time Capsule New",-53,"d0:84:b0:9b:93:a7",6) +CWLAP:(0,"Hotspot",-53,"52:84:b0:9b:93:a4",6) +CWLAP:(3,"Time",-53,"d0:84:b0:9b:93:a7",6)

Parse, all data no matter the String length. Oi WiFi Fon Time Capsule New Hotspot Time

String wifi_redes = "+CWLAP:(0,\"Oi WiFi Fon\",-53,\"52:84:b0:9b:93:a4\",6)\n+CWLAP:(3,\"Time Capsule New\",-53,\"d0:84:b0:9b:93:a7\",6)";

void setup() 
  Serial.begin(9600); // Initialize serial port to send and receive at 9600 baud

void loop()

  int firstClosingBracket = wifi_redes.indexOf('"');
  int secondClosingBracket = wifi_redes.indexOf('"', firstClosingBracket + 1 );

  String secondValue = wifi_redes.substring(firstClosingBracket+1, secondClosingBracket);


It is not good practice to use Strings (capital S) in the small memory of an Arduino. The code in Serial Input Basics uses strings (small s - arrays of char terminated with a 0) and includes a parse example.


Well, this is what I did, seams to work fine:

while (enable)
    firstClosingBracket = wifi_redes.indexOf('"');
    secondClosingBracket = wifi_redes.indexOf('"', firstClosingBracket + 1 );
    secondValue = wifi_redes.substring(firstClosingBracket + 1, secondClosingBracket);


    if (wifi_redes.indexOf('\n') > 0)
      wifi_redes = wifi_redes.substring(wifi_redes.indexOf('\n'));
      wifi_redes_new = "";
      firstClosingBracket, secondClosingBracket = 0;
      secondValue = "";
      enable = false;

You should be able to look for longer character strings instead of a single character like below (note more than one character will use double quotes instead of a single quote, and a back slash is used to escape special characters in the searched string of characters).

firstClosingBracket = wifi_redes.indexOf("Oi WiFi Fon\",");