I am using Arduino Uno with Sim900 GSM board. In my code I use the command AT+CGSN to retrieve the IMEI from the chip. This is (in my case) a 15 digit number sequence returned as: 
AT+CGSN

013949150670600

OK

This is received by:

```
void GetID(){
 GPRS.print("");   
  GPRS.println("AT+CGSN");    
  delay(200);    
 {    
  while(!GPRS.available());    
  if(GPRS.available()){    
    while(GPRS.available()){    
      imei_character = GPRS.read();    
      imei_content.concat(imei_character);    
//      delay(20);    
//      imei_content.trim();    
//      delay(20);      
    }
  }
  delay(1500);

} 

}

```

I have used .length() to determine that there are at least 10 whitespaces within the response, which puts the first digit at position 11. I know that to just parse the numbers I can use: 

```
 String getGSMid(){  
return imei_content.substring(11, 25);
}

```

or alternatively I can turn off command echo to remove the "AT+CSGN" then use "imei\_content.trim();" to remove the leading whitespace and from there use
 return imei\_content.substring(0, 15); instead.

What I would prefer through is to look at the response regardless of what it is and find the sequence of digits and extract it based on the fact that it is a digit, to the effect of:

```
    String getGSMid(){         
  return imei_content.substring(imei_content.indexOf('0>='),         imei_content.lastIndexOf('0>='));        
}

```

I am a novice coder, so although I have seen the likes of isdigit(), Regex, Sscanf, I am not sure if any are appropriate for my application. Ideally I would like to avoid adding a library and to keep the code as simple as possible. If I can adapt what I have to make a robust piece of code that will reliably parse the 15 digit id regardless of the return format (I realise that if there are any stray digits returned, which are not part of the ID this may throw things out, this is acceptable). It may be that disabling echo and trimming is the easiest way forward and "reliable enough" - hopefully someone can lead me in the right direction. Thank you.