String Character Length: Difference between revisions
Content added Content deleted
m (→[[Java]]: Use Java header instead) |
m (Switch to header template) |
||
Line 5: | Line 5: | ||
For byte length, see [[String Byte Length]]. |
For byte length, see [[String Byte Length]]. |
||
== |
=={{header|ActionScript}}== |
||
[[Category:ActionScript]] |
|||
myStrVar.length() |
myStrVar.length() |
||
== |
=={{header|Ada}}== |
||
[[Category:Ada]] |
|||
'''Compiler:''' GCC 4.1.2 |
'''Compiler:''' GCC 4.1.2 |
||
Line 17: | Line 14: | ||
Length : constant Natural := Str'Length; |
Length : constant Natural := Str'Length; |
||
== |
=={{header|AppleScript}}== |
||
[[Category:AppleScript]] |
|||
count of "Hello World" |
count of "Hello World" |
||
Line 24: | Line 20: | ||
count "Hello World" |
count "Hello World" |
||
== |
=={{header|AWK}}== |
||
[[Category:AWK]] |
|||
From within any code block: |
From within any code block: |
||
w=length("Hello, world!") # static string example |
w=length("Hello, world!") # static string example |
||
Line 37: | Line 32: | ||
{print"The length of this line is "length($0)} |
{print"The length of this line is "length($0)} |
||
== |
=={{header|C}}== |
||
[[Category:C]] |
|||
'''Standard:''' [[ANSI C]] (AKA [[C89]]): |
'''Standard:''' [[ANSI C]] (AKA [[C89]]): |
||
Line 96: | Line 89: | ||
} |
} |
||
== |
=={{header|Objective-C}}== |
||
[[Category:Objective-C]] |
|||
// Return the length in unicode characters |
// Return the length in unicode characters |
||
unsigned length = [@"Hello Word!" length]; |
unsigned length = [@"Hello Word!" length]; |
||
Line 128: | Line 119: | ||
} |
} |
||
== |
=={{header|C sharp|C#}}== |
||
[[Category:C sharp]] |
|||
'''Platform:''' [[.NET]] |
'''Platform:''' [[.NET]] |
||
'''Language Version:''' 1.0+ |
'''Language Version:''' 1.0+ |
||
Line 150: | Line 139: | ||
Start = strlen "Hello, world!" |
Start = strlen "Hello, world!" |
||
== |
=={{header|ColdFusion}}== |
||
[[Category:ColdFusion]] |
|||
#len("Hello World")# |
#len("Hello World")# |
||
== |
=={{header|Common Lisp}}== |
||
[[Category:Common Lisp]] |
|||
(length "Hello World") |
(length "Hello World") |
||
== |
=={{header|Component Pascal}}== |
||
[[Category:Component Pascal]] |
|||
LEN("Hello, World!") |
LEN("Hello, World!") |
||
== |
=={{header|E}}== |
||
[[Category:E]] |
|||
"Hello World".size() |
"Hello World".size() |
||
== |
=={{header|Forth}}== |
||
[[Category:Forth]] |
|||
The 1994 ANS standard does not have any notion of a particular character encoding, although it distinguishes between character and machine-word addresses. (There is some ongoing work on standardizing an "XCHAR" wordset for dealing with strings in particular encodings such as UTF-8.) |
The 1994 ANS standard does not have any notion of a particular character encoding, although it distinguishes between character and machine-word addresses. (There is some ongoing work on standardizing an "XCHAR" wordset for dealing with strings in particular encodings such as UTF-8.) |
||
Line 198: | Line 177: | ||
repeat drop ; |
repeat drop ; |
||
== |
=={{header|Haskell}}== |
||
[[Category:Haskell]] |
|||
'''Interpreter:''' [[GHC | GHCi]] 6.6, [[Hugs]] |
'''Interpreter:''' [[GHC | GHCi]] 6.6, [[Hugs]] |
||
Line 207: | Line 184: | ||
strlen = length "Hello, world!" |
strlen = length "Hello, world!" |
||
== |
=={{header|IDL}}== |
||
[[Category:IDL]] |
|||
'''Compiler:''' any IDL compiler should do |
'''Compiler:''' any IDL compiler should do |
||
Line 227: | Line 202: | ||
int length2 = str.codePointCount(0, str.length()); //1 |
int length2 = str.codePointCount(0, str.length()); //1 |
||
== |
=={{header|JavaScript}}== |
||
[[Category:JavaScript]] |
|||
JavaScript encodes strings in UTF-16, which represents each character with one or two 16-bit values. The most commonly used characters are represented by one 16-bit value, while rarer ones like some mathematical symbols are represented by two. |
JavaScript encodes strings in UTF-16, which represents each character with one or two 16-bit values. The most commonly used characters are represented by one 16-bit value, while rarer ones like some mathematical symbols are represented by two. |
||
Line 239: | Line 212: | ||
var len2 = str2.length; //2 |
var len2 = str2.length; //2 |
||
== |
=={{header|JudoScript}}== |
||
[[Category:JudoScript]] |
|||
//Store length of hello world in length and print it |
//Store length of hello world in length and print it |
||
. length = "Hello World".length(); |
. length = "Hello World".length(); |
||
Line 249: | Line 220: | ||
" Hello world" @ , # 11 |
" Hello world" @ , # 11 |
||
== |
=={{Lua}}== |
||
[[Category:Lua]] |
|||
'''Interpreter:''' [[Lua]] 5.0 or later. |
'''Interpreter:''' [[Lua]] 5.0 or later. |
||
Line 257: | Line 227: | ||
length=#string |
length=#string |
||
== |
=={{header|MAXScript}}== |
||
[[Category:MAXScript]] |
|||
"Hello world".count |
"Hello world".count |
||
== |
=={{header|mIRC Scripting Language}}== |
||
[[Category:mIRC Scripting Language]] |
|||
'''Interpreter:''' [[mIRC]] |
'''Interpreter:''' [[mIRC]] |
||
alias stringlength { echo -a Your Name is: $len($$?="Whats your name") letters long! } |
alias stringlength { echo -a Your Name is: $len($$?="Whats your name") letters long! } |
||
== |
=={{header|OCaml}}== |
||
[[Category:OCaml]] |
|||
'''Interpreter'''/'''Compiler:''' [[Ocaml]] 3.09 |
'''Interpreter'''/'''Compiler:''' [[Ocaml]] 3.09 |
||
Line 275: | Line 241: | ||
== |
=={{header|Perl}}== |
||
[[Category:Perl]] |
|||
'''Interpreter:''' [[Perl]] any 5.X |
'''Interpreter:''' [[Perl]] any 5.X |
||
my $length = length "Hello, world!"; |
my $length = length "Hello, world!"; |
||
== |
=={{header|PHP}}== |
||
[[Category:PHP]] |
|||
$length = strlen('Hello, world!'); |
$length = strlen('Hello, world!'); |
||
== |
=={{header|PL/SQL|PL/SQL}}== |
||
[[Category:PL/SQL|PL/SQL]] |
|||
DECLARE |
DECLARE |
||
string VARCHAR2( 50 ) := 'Hello, world!'; |
string VARCHAR2( 50 ) := 'Hello, world!'; |
||
Line 296: | Line 257: | ||
END; |
END; |
||
== |
=={{header|Python}}== |
||
[[Category:Python]] |
|||
'''Interpreter:''' [[Python]] 2.4 |
'''Interpreter:''' [[Python]] 2.4 |
||
Line 311: | Line 270: | ||
</pre> |
</pre> |
||
== |
=={{header|Ruby}}== |
||
[[Category:Ruby]] |
|||
'''Library:''' [[active_support]] |
'''Library:''' [[active_support]] |
||
Line 318: | Line 276: | ||
puts "Hello World".chars.length |
puts "Hello World".chars.length |
||
== |
=={{header|Scheme}}== |
||
[[Category:Scheme]] |
|||
(string-length "Hello world") |
(string-length "Hello world") |
||
== |
=={{header|Seed7}}== |
||
[[Category:Seed7]] |
|||
length("Hello, world!") |
length("Hello, world!") |
||
== |
=={{header|Smalltalk}}== |
||
[[Category:Smalltalk]] |
|||
string := 'Hello, world!". |
string := 'Hello, world!". |
||
string size. |
string size. |
||
== |
=={{header|Standard ML}}== |
||
[[Category:Standard ML]] |
|||
'''Interpreter:''' [[Standard ML of New Jersey | SML/NJ]] 110.60, [[Moscow ML]] 2.01 (January 2004) |
'''Interpreter:''' [[Standard ML of New Jersey | SML/NJ]] 110.60, [[Moscow ML]] 2.01 (January 2004) |
||
Line 343: | Line 293: | ||
val strlen = size "Hello, world!"; |
val strlen = size "Hello, world!"; |
||
== |
=={{header|Tcl}}== |
||
[[Category:Tcl]] |
|||
Basic version: |
Basic version: |
||
Line 358: | Line 306: | ||
puts [format "length of \"%s\" in characters is %d" $s2 [string length $s2]] |
puts [format "length of \"%s\" in characters is %d" $s2 [string length $s2]] |
||
== |
=={{header|UNIX Shell}}== |
||
[[Category:UNIX Shell]] |
|||
With external utilities: |
With external utilities: |
||
'''Interpreter:''' any |
'''Interpreter:''' any [[Bourne Shell]] |
||
string='Hello, world!' |
string='Hello, world!' |
||
Line 378: | Line 324: | ||
== |
=={{header|VBScript}}== |
||
[[Category:VBScript]] |
|||
Len(string|varname) |
Len(string|varname) |
||
Line 385: | Line 330: | ||
Returns null if string|varname is null |
Returns null if string|varname is null |
||
== |
=={{header|xTalk}}== |
||
[[Category:xTalk]] |
|||
'''Interpreter:''' HyperCard |
'''Interpreter:''' HyperCard |
||