Working with strings and functions

Hi to everybody,
I am quite new to arduino and need some help with a function.

i have this function:

void sendSms(String smsNumber, String smsText)
{
  Serial.println("\n--- SEND SMS START ---");
  digitalWrite(LED_BUILTIN, HIGH);

  myGsm.write("AT+CMGF=1\r");
  waitSerial("OK");

  myGsm.write("AT+CMGS="+smsNumber+"\r");
  waitSerial(">");  

  myGsm.write(smsText);
  myGsm.write(0x1A);
  waitSerial("OK");  

  Serial.println("--- SEND SMS END ---");
  digitalWrite(LED_BUILTIN, LOW);
}

from another function want to use the above as sendSms("to number", "with sms text this");

can not do that, getting many errors.

First of all how do i join strings as this "AT+CMGS="+smsNumber+"\r" is wrong!

Also why Serial.Write() works ok if i put a string e.g. Serial.Write("some text"); but not if i try to use a String variable e.g. myGsm.write(smsText);

What am i doing wrong?

Thank you all in advance.

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.

To be honest, if that was my project I would create a global char array to hold the message and then it would be directly accessible from the function.

...R

Thank you Robin2 for your comments, solved my problem with Serial.print(), just found out that the write() functions sends bytes and that was my problem.

Thank you again.