달나라 노트

Google Apps Script : charCodeAt (문자열에서 특정 위치에 있는 문자의 unicode 값 return) 본문

Google Apps Script

Google Apps Script : charCodeAt (문자열에서 특정 위치에 있는 문자의 unicode 값 return)

CosmosProject 2022. 11. 30. 20:04
728x90
반응형

 

 

 

String 객체의 charCodeAt method는 특정 위치(index)에 존재하는 문자의 unicode값을 return합니다.

 

 

Syntax

String.charCodeAt(index)

 

charCodeAt method는 string(문자)에 적용할 수 있습니다.

 

- index

parameter로서 숫자(index)를 전달할 수 있으며, 전달된 index 위치에 있는 문자의 unicode값을 return합니다.

 

 

 

function myFunction(){
  var test_string = 'This is my laptop. 이것은 나의 노트북입니다.';

  Logger.log(test_string.charCodeAt(0));
  Logger.log(test_string.charCodeAt(1));
  Logger.log(test_string.charCodeAt(3));
}


-- Result
84.0
104.0
115.0

 

test_string에 charCodeAt method를 적용한 예시입니다.

 

참고로 문자열에서 가장 첫 번째 글자는 index = 0입니다.

 

This is my laptop. 이것은 나의 노트북입니다.

즉, 위 문자열에서 가장 첫 글자인 T는 index = 0인 것이죠.

두 번째 글자인 h는 index = 1이고 이렇게 다음 글자로 갈수록 index가 1씩 늘어납니다.

 

 

- test_string.charCodeAt(0)

index = 0 위치에 있는 글자는 T입니다.

따라서 charCodeAt method의 결과로는 T의 unicode number인 84가 return됩니다.

 

 

 

 

 

 

728x90
반응형
Comments