indexOf()

描述

在原字串中尋找字元或另一個字串。預設是從原字串開頭開始尋找,或者你也可以從指定的起始位置開始尋找。

語法


string.indexOf(val)
string.indexOf(val, from)

參數

string : String 物件 (字串)
val : 要尋找的值 – 字元或字串
from : 指定一個起始位置

回傳

在原字串中,指定值所在的位置。如果沒找到則回傳 -1。

範例

StringIndexOf

See also

String
lastIndexOf()
startsWith()
endsWith()


語法參考主頁面

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.