Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Carriage Return <CR> and CTRL-Z to a String in java

Tags:

java

I am working to send SMS using java program.

The AT command is supping as a string. But the string format should be like AT+CMGS="+33146290800"<CR>Please call me soon.<ctrl-Z>.

I have to create string with the Carriage Return and CTRL-Z character.

If I add 0x0D and 0x1A with the string.

output:

AT+CMGS="+33146290800"13Please call me soon.26

How can I achieve the task? Can anyone help me to find a way out.

like image 531
Shantanu Banerjee Avatar asked Mar 03 '26 09:03

Shantanu Banerjee


1 Answers

To get this string:

"+33146290800"<CR>Please call me soon.<ctrl-Z>

You use this string literal:

String s = "\"+33146290800\"\rPlease call me soon.\u001A";

\" is the Java string literal escape sequence for a double quote, \r is escape sequence a carriage return, and \u0026 is the Java string literal Unicode escape sequence for character x1A (decimal 26), e.g., Ctrl+Z. More to explore in the JLS.

like image 51
T.J. Crowder Avatar answered Mar 05 '26 23:03

T.J. Crowder