Operations on a string - memory problem ?

Hello,

I wrote simple webserver on ENC28j60. To arduino also is connected a cellphone.
Webserver parses querystring and fireing function to send sms.

I have to concat querystring, but I can save only string which length is <= 62. I think, that string is not good solution for this - any ideas ?

I’m getting from arduino this:

GET /?SMS78593244444789789796796796796796789789797897897890978 HTTP/1.1
Host: 192.168.1.25
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pl,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive

and I need to save to my variable a piece of first line.

My code

void loop () {
   
    word len = ether.packetReceive();
    word pos = ether.packetLoop(len);
  
      if(strstr((char *)Ethernet::buffer + pos, "GET /?SMS") != 0) {
        
        String str((char *)Ethernet::buffer + pos);
        Serial.println(str);


int index = str.indexOf(" HTTP");
Serial.println(index);

String number = str.substring(9,18);
Serial.println(number);
String message = str.substring(18,index);
Serial.println(message);
}
}

My output:

62        // index
785932444    // phone number
44789789796796796796796789789797897897890978     // text message

But I posted maximum length of text message. If I browse arduino page with one char more in query string, my message variable wll be empty , but why ?

Edit: I Can get a string with length between ~60 and ~64 - in each run of arduino program (after reset for example) those values are a bit different

Your post title says "Operations on a string", but your problems involve Strings. Quit using them. You already have the data in the best possible form - a string. That's a NULL terminated array of chars. Learn to work with strings.

http://www.gammon.com.au/forum/?id=12153#trap23

Ok, maybe you are right, but I do not understand, how it is possible: I saved buffer into string and I printed whole string to console (about 400 characters) - so string could be longer than 60-70 characters. So why substring function does not work properly when returns strings longer than ~60 characters...
I decided to use string because of well known methods like indexOf(), substring() etc...

I'm a c# programmer and I use strings rather than char arrays - I must learn a bit :slight_smile:

If someone has working examples of searching string in char array or parsing a query string of char array, please post here :slight_smile:

Great, Nick :wink: Thanks a lot.

You are probably best off decoding on-the-fly. Examples here:

I decided to use string because of well known methods like indexOf(), substring() etc...

All those methods operate on the char array that they have wrapped, using standard string handling functions. Learn to use those functions yourself! Stop pissing resources away.