String Character Length: Difference between revisions

Content deleted Content added
m →‎[[Java]]: Use Java header instead
m Switch to header template
Line 5:
For byte length, see [[String Byte Length]].
 
==[[{{header|ActionScript]]}}==
[[Category:ActionScript]]
myStrVar.length()
 
==[[{{header|Ada]]}}==
[[Category:Ada]]
 
'''Compiler:''' GCC 4.1.2
 
Line 17 ⟶ 14:
Length : constant Natural := Str'Length;
 
==[[{{header|AppleScript]]}}==
[[Category:AppleScript]]
count of "Hello World"
Line 24 ⟶ 20:
count "Hello World"
 
==[[{{header|AWK]]}}==
[[Category:AWK]]
From within any code block:
w=length("Hello, world!") # static string example
Line 37 ⟶ 32:
{print"The length of this line is "length($0)}
 
==[[{{header|C]]}}==
[[Category:C]]
 
'''Standard:''' [[ANSI C]] (AKA [[C89]]):
 
Line 96 ⟶ 89:
}
 
==[[{{header|Objective-C]]}}==
[[Category:Objective-C]]
 
// Return the length in unicode characters
unsigned length = [@"Hello Word!" length];
Line 128 ⟶ 119:
}
 
==[[{{header|C sharp|C#]]}}==
[[Category:C sharp]]
 
'''Platform:''' [[.NET]]
'''Language Version:''' 1.0+
Line 150 ⟶ 139:
Start = strlen "Hello, world!"
 
==[[{{header|ColdFusion]]}}==
[[Category:ColdFusion]]
 
#len("Hello World")#
 
==[[{{header|Common Lisp]]}}==
[[Category:Common Lisp]]
 
(length "Hello World")
 
==[[{{header|Component Pascal]]}}==
[[Category:Component Pascal]]
 
LEN("Hello, World!")
 
==[[{{header|E]]}}==
[[Category:E]]
 
"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.)
 
Line 198 ⟶ 177:
repeat drop ;
 
==[[{{header|Haskell]]}}==
[[Category:Haskell]]
 
'''Interpreter:''' [[GHC | GHCi]] 6.6, [[Hugs]]
 
Line 207 ⟶ 184:
strlen = length "Hello, world!"
 
==[[{{header|IDL]]}}==
[[Category:IDL]]
 
'''Compiler:''' any IDL compiler should do
 
Line 227 ⟶ 202:
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.
 
Line 239 ⟶ 212:
var len2 = str2.length; //2
 
==[[{{header|JudoScript]]}}==
[[Category:JudoScript]]
 
//Store length of hello world in length and print it
. length = "Hello World".length();
Line 249 ⟶ 220:
" Hello world" @ , # 11
 
==[[{{Lua]]}}==
[[Category:Lua]]
 
'''Interpreter:''' [[Lua]] 5.0 or later.
Line 257 ⟶ 227:
length=#string
 
==[[{{header|MAXScript]]}}==
[[Category:MAXScript]]
"Hello world".count
 
==[[{{header|mIRC Scripting Language]]}}==
[[Category:mIRC Scripting Language]]
 
'''Interpreter:''' [[mIRC]]
 
alias stringlength { echo -a Your Name is: $len($$?="Whats your name") letters long! }
 
==[[{{header|OCaml]]}}==
[[Category:OCaml]]
'''Interpreter'''/'''Compiler:''' [[Ocaml]] 3.09
 
Line 275 ⟶ 241:
 
 
==[[{{header|Perl]]}}==
[[Category:Perl]]
'''Interpreter:''' [[Perl]] any 5.X
 
my $length = length "Hello, world!";
 
==[[{{header|PHP]]}}==
[[Category:PHP]]
 
$length = strlen('Hello, world!');
 
==[[{{header|PL/SQL|PL/SQL]]}}==
[[Category:PL/SQL|PL/SQL]]
 
DECLARE
string VARCHAR2( 50 ) := 'Hello, world!';
Line 296 ⟶ 257:
END;
 
==[[{{header|Python]]}}==
[[Category:Python]]
 
'''Interpreter:''' [[Python]] 2.4
 
Line 311 ⟶ 270:
</pre>
 
==[[{{header|Ruby]]}}==
[[Category:Ruby]]
'''Library:''' [[active_support]]
 
Line 318 ⟶ 276:
puts "Hello World".chars.length
 
==[[{{header|Scheme]]}}==
[[Category:Scheme]]
 
(string-length "Hello world")
 
==[[{{header|Seed7]]}}==
[[Category:Seed7]]
 
length("Hello, world!")
 
==[[{{header|Smalltalk]]}}==
[[Category:Smalltalk]]
 
string := 'Hello, world!".
string size.
 
==[[{{header|Standard ML]]}}==
[[Category:Standard ML]]
 
'''Interpreter:''' [[Standard ML of New Jersey | SML/NJ]] 110.60, [[Moscow ML]] 2.01 (January 2004)
 
Line 343 ⟶ 293:
val strlen = size "Hello, world!";
 
==[[{{header|Tcl]]}}==
[[Category:Tcl]]
 
Basic version:
 
Line 358 ⟶ 306:
puts [format "length of \"%s\" in characters is %d" $s2 [string length $s2]]
 
==[[{{header|UNIX Shell]]}}==
[[Category:UNIX Shell]]
 
With external utilities:
 
'''Interpreter:''' any bourne[[Bourne shellShell]]
 
string='Hello, world!'
Line 378 ⟶ 324:
 
 
==[[{{header|VBScript]]}}==
[[Category:VBScript]]
Len(string|varname)
 
Line 385 ⟶ 330:
Returns null if string|varname is null
 
==[[{{header|xTalk]]}}==
[[Category:xTalk]]
 
'''Interpreter:''' HyperCard