Arduino String类构造方法和以及常用方法详解
🌼作为数据类型引用
String s1 = "hello";
//定义了一个String类型的变量s1并给它赋值内容。String thisString = String(13, HEX);
//等价于thisString=“d”String thisString = String(13, BIN);
//等价于thisString =“1101”
📑String()语法
String(val)
String(val, base)
String(val, decimalPlaces)
参数:
val
: a variable to format as a String. Allowed data types: string, char, byte, int, long, unsigned int, unsigned long, float, double.
base
: (optional) the base in which to format an integral value.
decimalPlaces
: only if val is float or double. The desired decimal places.
String stringOne = "Hello String"; //直接给String类变量赋值
String stringOne = String('a'); // 转单个字符为String类
String stringTwo = String("This is a string"); // 将字符串转成String类
String stringOne = String(stringTwo + " with more"); // string拼接
String stringOne = String(13);//将整型数13转成String并赋值给变量
String stringOne = String(analogRead(0), DEC);//将模拟量的数值赋值给变量
String stringOne = String(45, HEX); // 将整型数45转成16进制数并赋值给变量,
String stringOne = String(255, BIN); //将整型数255转成2进制数并赋值给变量,实际值stringOne=11111111
String stringOne = String(millis(), DEC); //将当前计时器的时间赋值给变量(long int类型转String)
String stringOne = String(5.698751, 3);//stringOne=5.698