String .length function not letting sketch compile

Hi Everyone!

I’m hoping this is some simple mistake on my part, I’ve been bashing my head against Strings for most of the afternoon and can’t seem to make any progress. :slight_smile:

Here’s a distilled version of my problem:

#include <WString.h>

char str1[] = "123456789A";

void setup()
{
    Serial.begin(9600);    
}

void loop()
{
  int i = str1.length();
}

Whenever I go to compile this I get:
In function ‘void loop()’:
error: request for member ‘length’ in ‘str1’, which is of non-class type ‘char [11]’

Searching the forums here, I found 2 changes that needed to be made to the WString library.
See the following pages:
…arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1241618944/11
…arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261015776
(Sorry, I can’t post links yet.) but even for those errors the sketch at least compiled.

Here’s my system: Macintosh G5 PowerPC, OS 10.4.11 running Arduino 0017.

All I really want to is to be able to find the length of a String (aka. char array) and then see if 2 strings are equivalent (which also won’t work for me). I suppose I can use For loops for everything, but I guess I’m kind of stubborn sometimes. :stuck_out_tongue:

Any ideas/suggestions/comments/criticisms/witty remarks are welcome!!! :smiley:

You need to allocate the string :

String str1 = String("123456789A");

But if all you want to do is find the length of a character array, you can do this:

char str1[] = "123456789A";
void setup()
{
    Serial.begin(9600);    
}

void loop()
{
  int i = strlen(str1);
}

Awesome!!! Thank you very very much Mem! Got it working now! :smiley: