본문 바로가기

코딩 놀이

arduino indexof() ,lastIndexOf()함수 (1)

학습하는 코딩언어의 함수(공식)를 많이 알고 있으면,  간단하고, 쉽고, 명료하게 작성 할 수 았습니다.   indexof() 공식은 많은 문자들의 모임(집합)에서 지정된 문자 위치를 알 수 있습니다.  

 

String st="qwertyhg";
void setup(){
Serial.begin(115200);
int x=st.indexOf('t');
Serial.println(x);
}
void loop(){}

결과: st="qwertyhg"; 집합 st 원소 t는 5번째 위치에 있습니다. 코딩에서는 항상 0부터 시작되므로 4가 됩니다.

 

lastIndexOf()는  뒤에서 부터 검색합니다. st 문자열에는 tt가 반복되어있을 겨우 뒤에 t를 지정합니다.

String st="qwerttyhg";

void setup(){
Serial.begin(115200);
int x=st.lastIndexOf('t');
Serial.println(x);
}
void loop(){}

'코딩 놀이' 카테고리의 다른 글

arduino 배열 (3)  (0) 2024.11.16
arduino substring() , substring(a,b)함수 (2)  (0) 2024.11.16
임시좌표  (0) 2023.11.28
G-code 9: G3, R,F  (0) 2023.07.01
G-code 8: G2, R, F  (0) 2023.07.01