Go Down

Topic: Beginner question about char. (Read 262 times) previous topic - next topic

khizon18

Hi.. I would like to know how to get character at specific array position to the last.. and covert is as a string..


Example: Char char1[50] = "Legend";


I want a Result:    String string1 = "gend";

Arrch


Hi.. I would like to know how to get character at specific array position to the last.. and covert is as a string..


You mean String. A string is a null-terminated array of chars like your first line. A String is an object with a well documented amount of issues.

Given

Code: [Select]
char char1[] = "Legend";

you can access a latter part of it by taking the address of the first array element:

Code: [Select]
Serial.println(&char1[2]);

Would produce "gend"

khizon18

wow thanks you... what if i only want "gen"?

Arrch

Replace the 'd' with a '\0' (null terminator).

Go Up