String 物件

描述

字串物件允許你使用比 字串陣列 更複雜的方式來操作字串。它可以連結字串、增加字串、搜尋字串、替換字串、等等…;相較於一般的字元陣列它會占用更多的記憶體空間,不過也更為有用。

僅供參考:以小寫 s 開頭的 string 字元陣列會被認為是字串,以大寫 S 開頭的 String 則是字串物件,注意字串常數會因為標記上雙引號而被當作字元陣列,而不是字串物件。

函式

String()
charAt()
compareTo()
concat()
endsWith()
equals()
equalsIgnoreCase()
getBytes()
indexOf()
lastIndexOf()
length()
replace()
reserve()
setCharAt()
startsWith()
substring()
toCharArray()
toInt()
toLowerCase()
toUpperCase()
trim()

運算子

[] (element access)
+ (concatenation)
== (comparison)

範例

下列 String 物件的範例來自 Arduino 教學網站,他們也可以在 86Duino 板上使用:

StringConstructors
StringAdditionOperator
StringIndexOf
StringAppendOperator
StringLengthTrim
StringCaseChanges
StringReplace
StringCharacters
StringStartsWithEndsWith
StringComparisonOperators
StringSubstring

See also

string: character arrays
Variable Declaration


語法參考主頁面

本頁由熱血青年 LBU 譯自英文版。

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.