함수 ord()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:33 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
  다른 뜻에 대해서는 객체 관계 데이터베이스 ORD 문서를 참조하십시오.
ord()
CODE()
codepoint()

1 Bash

CHR=A
ORD=`printf '%d' "'$CHR"`
echo $ORD
# 65

2 Excel

=CODE("A")
// 65

3 Java

System.out.println( (int) 'A' );
// 65
System.out.println( (int) '★' );
// 9733

4 JavaScript

document.write('A'.charCodeAt(0));
// 65

5 Lua

print( string.byte("A") )
// 65
print( string.byte("ABC") )
// 65
print( string.byte("가") )
// 234
Lua 5.3 이상
print( utf8.codepoint('A') )
// 65
print( utf8.codepoint('가') )
// 44032

6 Objective-C

#define CODE(x) (int)[x characterAtIndex:0]
int code = CODE(@"★");
NSLog(@"%d", code); // 9733
NSString* str = @"★";
int code = (int)[str characterAtIndex:0];
NSLog(@"%d", code); // 9733
int code = (int)'A';
NSLog(@"%d", code); // 65

7 Perl

print ord('A');
# 65

8 PHP

echo ord('A');
// 65

9 Python

print ord('A')
# 65

10 R

utf8ToInt('A')
## [1] 65
utf8ToInt('★')
## [1] 9733
utf8ToInt('👍')
## [1] 128077

11 Ruby

Ruby 1.8
puts 'A'[0]
# 65
Ruby 1.9
puts 'A'.ord
# 65

12 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}