转换一个int或字符串在Arduino的字符数组 [英] Converting an int or String to a char array on Arduino
问题描述
我正在从我的Arduino模拟引脚的一个int值。我如何串连给字符串
然后转换字符串
到的char []
?
有人建议我尝试味精的char [] = myString.getChars();
,但我接收则GetChars 消息code>不存在。
-
要转换并追加一个整数,使用的 运算符+ = 的(或成员函数
CONCAT
)字符串stringOne =一个长整型;
stringOne + = 123456789; -
要得到字符串类型
的char []
,使用 toCharArray():字符charBuf [50];
stringOne.toCharArray(charBuf,50)
在该示例中,仅存在49个字符(presuming它是由空终止)的空间。你可能想使大小动态。
I am getting an int value from one of the analog pins on my Arduino. How do I concatenate this to a String
and then convert the String
to a char[]
?
It was suggested that I try char msg[] = myString.getChars();
, but I am receiving a message that getChars
does not exist.
To convert and append an integer, use operator += (or member function
concat
):String stringOne = "A long integer: "; stringOne += 123456789;
To get the string as type
char[]
, use toCharArray():char charBuf[50]; stringOne.toCharArray(charBuf, 50)
In the example, there is only space for 49 characters (presuming it is terminated by null). You may want to make the size dynamic.
这篇关于转换一个int或字符串在Arduino的字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!