Extracting part of a String


I have two strings as follows:

String abc ="123456789"; //this string always hold numbers

String def; //this one will be converted later to INT

and would like to extract the 1'st 5 characters from string abc and put it in string def for further processing.

So, substring is out of the question because there is no special character I can use for a reference. And can't find a suitable command to do it.

Any help is appreciated.

This will be helpful to you:

Of course you should just use char arrays instead, which can be manipulated in the same way:

Why is substring out of the question?


This is a case where it's actually a lot easier if you get rid of the String class. If that's in a char array then all you have to do is grab the first five elements of the char array. You don't need any special functions or anything.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.


Array did it for me.

Thanks Pert and all.