Arduino String
构造 String 类的实例。有多个版本可以从不同的数据类型构造字符串(即,将它们格式化为字符序列),包括:
- 用双引号括起来的常量字符串(即字符数组)
- 单个常量字符(用单引号引起来)
- String 对象的另一个实例
- 常数整数或长整数
- 使用指定基数的常量整数或长整数
- 整数或长整数变量
- 使用指定基数的整数或长整数变量
- 浮点数或双精度数,使用指定的小数位
从数字构造字符串会产生一个包含该数字的 ASCII 表示的字符串。默认为十进制,因此
String thisString = String(13);
但是,你可以使用其他进制。例如,
String thisString = String(13, HEX);
给出字符串“d”,它是十进制值 13 的十六进制表示形式。或者如果你更喜欢二进制,
String thisString = String(13, BIN);
给出字符串“1101”,它是 13 的二进制表示形式。val
- :要格式化为字符串的变量。允许的数据类型:string char、byte、int、long、unsigned int、unsigned long、float、double。base
- :(可选)格式化整数值的进制。decimalPlaces
- :仅当 val 是 float 或 double 时。所需的小数位数。
string(字符串,进制,float或double时的小数位)
String stringOne = "Hello String"; // using a constant String String stringOne = String('a'); // converting a constant char into a String String stringTwo = String("This is a string"); // converting a constant string into a String object String stringOne = String(stringTwo + " with more"); // concatenating two strings String stringOne = String(13); // using a constant integer String stringOne = String(analogRead(0), DEC); // using an int and a base String stringOne = String(45, HEX); // using an int and a base (hexadecimal) String stringOne = String(255, BIN); // using an int and a base (binary) String stringOne = String(millis(), DEC); // using a long and a base String stringOne = String(5.698, 3); // using a float and the decimal places
function:
- charAt()
- compareTo()
- concat()
- c_str()
- endsWith()
- equals()
- equalsIgnoreCase()
- getBytes()
- indexOf()
- lastIndexOf()
- length()
- remove()
- replace()
- reserve()
- setCharAt()
- startsWith()
- substring()
- toCharArray()
- toDouble()
- toInt()
- toFloat()
- toLowerCase()
- toUpperCase()
- trim()
Operators
- [] (element access)
- + (concatenation)
- += (append)
- == (comparison)
- > (greater than)
- >= (greater than or equal to)
- < (less than)
- <= (less than or equal to)
- != (different from)
浙公网安备 33010602011771号