Google Apps Script
Google Apps Script : charAt (문자열에서 특정 위치에 있는 문자 return)
CosmosProject
2022. 11. 30. 19:56
728x90
반응형
String 객체의 charAt method는 특정 위치(index)에 존재하는 문자를 return합니다.
Syntax
String.charAt(index)
charAt method는 string(문자)에 적용할 수 있습니다.
- index
parameter로서 숫자(index)를 전달할 수 있으며, 전달된 index 위치에 있는 문자를 return합니다.
function myFunction(){
var test_string = 'This is my laptop. 이것은 나의 노트북입니다.';
Logger.log(test_string.charAt(0));
Logger.log(test_string.charAt(1));
Logger.log(test_string.charAt(3));
}
-- Result
T
h
s
test_string에 charAt method를 적용한 예시입니다.
참고로 문자열에서 가장 첫 번째 글자는 index = 0입니다.
This is my laptop. 이것은 나의 노트북입니다.
즉, 위 문자열에서 가장 첫 글자인 T는 index = 0인 것이죠.
두 번째 글자인 h는 index = 1이고, 이렇게 다음 글자로 갈수록 index가 1씩 늘어납니다.
- test_string.charAt(0)
따라서 위 코드의 결과는 T가 return된 것을 볼 수 있습니다.
728x90
반응형