string and char array

hello guys, I'm new in programming and today I have 2 question about string and char array. here is my first question :

suppose I had the following data (the data is in sting format) : M181997
from the data above I want to make something like this

Serial.print("GENDER : ");
Serial.println(first character of my string data);
Serial.print("AGE : ");
Serial.println(second and third character of my string data);
Serial.print(BIRTH YEAR : );
Serial.println(fourth, fifth, sixth and seventh character of my string data);

And I'm expecting something like this to be displayed on my Serial monitor :

GENDER : M
AGE : 18
BIRTH YEAR : 1997

and my second question is : how can I convert a string into an array? let's say I have string like this :

String myMessage="ARDUINOUNO"

now I want to convert it into something like this :

Char myMessage[11] = {"ARDUINOUNO"};

This illustrates how to convert:

void setup() {

  Serial.begin(9600);

  char myCharArray[11];
  String myMessage="ARDUINOUNO";

  myMessage.toCharArray(myCharArray, 11);  // display it once
  Serial.println(myCharArray);

  for (int i = 0; myCharArray[i]; i++)     // prove it's an array
    Serial.print(myCharArray[i]);

}

void loop() {

}

You should note the size difference when you convert from using the String class to a char array. The char array will save you memory.

and my second question is : how can I convert a string into an array?

There is no need. A string is a NULL terminated array of chars. A String is something else entirely, and really has no place on the Arduino.

econjack:
This illustrates how to convert:

void setup() {

Serial.begin(9600);

char myCharArray[11];
 String myMessage="ARDUINOUNO";

myMessage.toCharArray(myCharArray, 11);  // display it once
 Serial.println(myCharArray);

for (int i = 0; myCharArray[i]; i++)     // prove it's an array
   Serial.print(myCharArray[i]);

}

void loop() {

}

Thank you sir, this is what I've been looking for.

As Paul suggested, there is no need for the String in the first place.
Why not just

void setup() 
{
  Serial.begin(115200);
  char myCharArray[] = "ARDUINOUNO";
  Serial.println(myCharArray);
}

void loop() 
{
}

Incidentally, what values of i do you expect to get from

for (int i = 0; myCharArray[i]; i++)

Have you tried printing them ?

Incidentally, what values of i do you expect to get from

As long as the ith element of the array is not NULL, the middle clause of the for statement will evaluate to true. I don't like that structure. It looks like a mistake, even though it isn't.

As long as the ith element of the array is not NULL, the middle clause of the for statement will evaluate to true.

Got it, thanks.

I don't like that structure.

Me neither, even though I now understand how it works.

I don't like that structure.

Why not? What about:

  for (int i = 0; myCharArray[i] != '\0'; i++)     // prove it's an array

econjack:
Why not? What about:

  for (int i = 0; myCharArray[i] != '\0'; i++)     // prove it's an array

Yes. The code should "speak" the coders intentions to the reader, not just the compiler.