友情提示:380元/半年,儿童学编程,就上码丁实验室。
改变字符串状态的函数
- String case change函数允许你改变字符串的状态。它们就像名字暗示的那样工作。toUpperCase()把所有字符串改为大写字母,而toLowerCase()把所有字符串改为小写字母。只有 A 到Z 或者 a 到 z的字符受到影响。
硬件要求
- Arduino or Genuino开发板
电路
- 这个例子不需要连接额外的电路,除了你的开发板需要连接到你的电脑,并且打开Arduino IDE的串口监视器窗口。
图由 Fritzing 软件绘制
样例代码
/*
String Case changes
Examples of how to change the case of a string
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringCaseChanges
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// send an intro:
Serial.println("nnString case changes:");
Serial.println();
}
void loop() {
// toUpperCase() changes all letters to upper case:
String stringOne = "<html><head><body>";
Serial.println(stringOne);
stringOne.toUpperCase();
Serial.println(stringOne);
// toLowerCase() changes all letters to lower case:
String stringTwo = "</BODY></HTML>";
Serial.println(stringTwo);
stringTwo.toLowerCase();
Serial.println(stringTwo);
// do nothing while true:
while (true);
}
更多
- String object – 字符串对象的参考
- CharacterAnalysis – 使用operators来识别对应的特征类型。
- StringAdditionOperator – 用不同方法把字符串加到一起。
- StringAppendOperator – 用+=运算符和concat()方法来添加东西到字符串里。
- StringCaseChanges – 改变字符串的状态。
- StringCharacters – 在字符串里获得或设置一个指定的字符的值
- StringComparisonOperators – 按字母排列顺序地比较字符串
- StringConstructors – 初始化字符串对象
- StringIndexOf – 寻找在字符串里字符的第一个或最后一个的状态
- StringLength – 获得和修剪字符串的长度
- StringLengthTrim – 获得和修剪字符串的长度
- StringReplace – 替换字符串里的个别字符
- StringStartsWithEndsWith – 检查一个给定的字符或子串(substrings)的开始或结尾
- StringSubstring – 在给定的字符串里寻找”phrases”
- StringToInt – 允许你把字符串转换成整数数字