"함수 CharAt()"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
[[category: String]]
[[category: string]]
==개요==
;charAt
;characterAtIndex
*Returns character at index in the string.
*Equivalent: See [[substring]] of length 1 character.


==JavaScript==
==ALGOL 68==
[[category: JavaScript]]
[[category: ALGOL 68]]
<source lang='JavaScript'>
<source lang="html4strict">
var str = "HELLO WORLD";
"Hello, World"[2];        // 'e'
console.log( str.charAt(1) );
</source >
// E
 
==C#==
[[category: Csharp]]
<source lang="csharp">
string str = "Hello, World";
char ch = str[1];
// 'e'
</source>
 
==Excel==
[[category: Excel]]
<source lang='php'>
=MID("hello",1,1)
// h
=MID("hello",2,1)
// e
=MID("hello",3,1)
// l
</source>
 
==Java==
[[category: Java]]
<source lang='java'>
String str = "Hello, World";
str.charAt(2);  // 'l'
</source>
 
==Javascript==
[[category: Javascript]]
<source lang='javascript'>
var str = "Hello, World";
str.charAt(2);  // 'l'
</source>
 
==Objective-C==
[[category: Objective-C]]
<source lang='objc'>
#define CHAR_AT(str, n) [str substringWithRange:NSMakeRange(n,1)]
NSString* ch = CHAR_AT(@"A가★あ中", 2);
NSLog(@"%@", ch); // ★
</source>
<source lang='objc'>
NSString* str = @"A가★あ中";
unichar ch = [str characterAtIndex:2];
NSLog(@"%C", ch); //
</source>
</source>
==Pascal==
[[category: Pascal]]
<source lang="pascal">
var
  MyStr: string = 'Hello, World';
  MyChar: Char;
begin
  MyChar := MyStr[2];        // 'e'
</source >
==Perl==
[[category: Perl]]
<source lang='perl'>
$str = 'Hello, World';
substr($str, 2, 1);  # 'l'
substr($str, -3, 1); # 'r'
</source>
==PHP==
[[category: PHP]]
<source lang='php'>
$str = "Hello";
$ch = $str[1];
// e
</source>
==Python==
[[category: Python]]
<source lang="python">
"Hello, World"[2]          #  'l'
"Hello, World"[-3]        #  'r'
</source>
==Ruby==
[[category: Ruby]]
<source lang="ruby">
"Hello, World"[2]          #  'l'
"Hello, World"[-3]        #  'r'
</source>
==Smalltalk==
[[category: Smalltalk]]
<source lang="smalltalk">
'Hello, World' at: 2.    "$e"
</source>
==VB==
[[category: VB]]
<source lang="vb">
GetChar("Hello, World", 2) '  "e"
</source>
==VB.NET==
[[category: VB.Net]]
<source lang="vbnet">
"Hello, World".Chars(2)    '  "l"
</source>
==같이 보기==
*[[utf8 charAt]]
*[[substr]]
*[[charCodeAt]]
==참고 자료==
*http://eqcode.com/wiki/CharAt

2014년 8월 24일 (일) 23:40 판

1 개요

charAt
characterAtIndex
  • Returns character at index in the string.
  • Equivalent: See substring of length 1 character.

2 ALGOL 68

"Hello, World"[2];         // 'e'

3 C#

string str = "Hello, World";
char ch = str[1];
// 'e'

4 Excel

=MID("hello",1,1)
// h
=MID("hello",2,1)
// e
=MID("hello",3,1)
// l

5 Java

String str = "Hello, World";
str.charAt(2);  // 'l'

6 Javascript

var str = "Hello, World";
str.charAt(2);  // 'l'

7 Objective-C

#define CHAR_AT(str, n) [str substringWithRange:NSMakeRange(n,1)]
NSString* ch = CHAR_AT(@"A가★あ中", 2);
NSLog(@"%@", ch); // ★
NSString* str = @"A가★あ中";
unichar ch = [str characterAtIndex:2];
NSLog(@"%C", ch); // ★

8 Pascal

var 
  MyStr: string = 'Hello, World';
  MyChar: Char;
begin
  MyChar := MyStr[2];         // 'e'

9 Perl

$str = 'Hello, World';
substr($str, 2, 1);  # 'l'
substr($str, -3, 1); # 'r'

10 PHP

$str = "Hello";
$ch = $str[1];
// e

11 Python

"Hello, World"[2]          #  'l'
"Hello, World"[-3]         #  'r'

12 Ruby

"Hello, World"[2]          #  'l'
"Hello, World"[-3]         #  'r'

13 Smalltalk

'Hello, World' at: 2.    "$e"

14 VB

GetChar("Hello, World", 2) '  "e"

15 VB.NET

"Hello, World".Chars(2)    '  "l"

16 같이 보기

17 참고 자료