I am sending letter A (string letter = "A\n") on my android phone to a device. In matlab the code is set(s1,'Terminator', 'CR'). I would like to know how this is done from on an android phone. I want an enter after I sending letter A. Thanks for you answers in advance
Asked
Active
Viewed 208 times
2 Answers
1
I have found the answer. "\n" is new line feed, "\r" is carriage return. "\n" = 10 in decimal; and "\r" = 13 in decimal. so I want 13 in decimal for Carriage return, "\r" worked for me instead of "\n". (Look at the ASCII table closer :))

BioengineerDavid
- 23
- 1
- 9
-
if you find this helpful, please vote the answer up so I can build my reputation on stack overflow. – BioengineerDavid Aug 25 '13 at 10:04
0
String num = String.valueOf(number);
String cr = String.valueOf(number_cr);
String s = num + "\n" + cr;
or you can try something like:
String eol = System.getProperty("line.separator");
String s = num + eol + cr;
See How to insert a new line in strings in Android for more. Hope it helps.

Community
- 1
- 1

Shobhit Puri
- 25,769
- 11
- 95
- 124
-
I tried the two ways you suggested but it didnt work for me. String s to decimal 65 10 but I want 65 13 (13 is carriage return) – BioengineerDavid Aug 18 '13 at 11:13
-
i am trying both the methods and they seems to work. Check it yourself. Run the code here: http://rextester.com/live/ZLN61101 – Shobhit Puri Aug 18 '13 at 11:17
-
You can first try to convert those integers to string using `String.valueOf(number)` and then use them – Shobhit Puri Aug 18 '13 at 11:18
-
I have found the answer. "\n" is new line feed, "\r" is carriage return. "\n" = 10; and "\r" = 13. so I want 13, "\r" worked for me instead of "\n" – BioengineerDavid Aug 18 '13 at 11:37
-
Great. You can post that as a new answer. This would help those who would come to this thread in future. Thanks :) – Shobhit Puri Aug 18 '13 at 11:38