ForNext
Only Do What Only You Can Do
068. 文字列リテラルの大きさを表示する
VBScript
JScript
Perl
更新日 : 2010.10.18
$n = length("123"); print "length('123') = $n \n";
L:\>perl lesson_09_068.pl length('123') = 3
PHP
更新日 : 2010.11.03
<?php $n = strlen("123"); print "length('123') = $n \n"; ?>
L:\>php lesson_09_068.php length('123') = 3
Python
更新日 : 2010.11.17
n = len("123") print "length('123') = %d" % n
N:\>python lesson_09_068.py length('123') = 3
Ruby
更新日 : 2010.11.01
n = "123".length print "length('123') = #{n} \n" n = "123".size print "size('123') = #{n} \n"
L:\>ruby l:\lesson_09_068.rb length('123') = 3 size('123') = 3
PowerShell
Scala
F#
C
更新日 : 2010.10.08
#include <stdio.h> int main(int argc, char* argv[]) { printf("sizeof(\"123\") = %u\n", (unsigned)sizeof("123")); printf("sizeof(\"AB\\tC\") = %u\n", (unsigned)sizeof("AB\tC")); printf("sizeof(\"abc\\0def\") = %u\n", (unsigned)sizeof("abc\0def")); return 0; }
R:\>lesson068\Project1.exe sizeof("123") = 4 sizeof("AB\tC") = 5 sizeof("abc\0def") = 8
C++
C++Builder
VC++
C#
Java
更新日 : 2010.11.05
import java.util.Scanner; class Lesson068 { public static void main(String[] args) { System.out.printf("sizeof(\"123\") = %d\n", "123".length()); System.out.printf("sizeof(\"AB\\tC\") = %d\n", "AB\tC".length()); System.out.printf("sizeof(\"abc\\0def\") = %d\n", "abc\0def".length()); } }
L:\>java Lesson068 sizeof("123") = 3 sizeof("AB\tC") = 4 sizeof("abc\0def") = 7
Objective-C
D
VB
VB.NET
Delphi
更新日 : 2010.09.24
program Project1; {$APPTYPE CONSOLE} uses SysUtils; procedure main(); begin Writeln(Format('sizeof("123") = %d', [SizeOf('123')])); Writeln(Format('sizeof("AB\tC") = %d', [SizeOf('AB'#9'C')])); Writeln(Format('sizeof("abc\0def") = %d', [SizeOf('abc'#0'def')])); Writeln(''); Writeln(Format('sizeof("123") = %d', [Length('123')])); Writeln(Format('sizeof("AB\tC") = %d', [Length('AB'#9'C')])); Writeln(Format('sizeof("abc\0def") = %d', [Length('abc'#0'def')])); end; begin main; end.
S:\>lesson068\Project1.exe sizeof("123") = 4 sizeof("AB\tC") = 4 sizeof("abc\0def") = 4 sizeof("123") = 3 sizeof("AB\tC") = 4 sizeof("abc\0def") = 7