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]].


==[[ActionScript]]==
=={{header|ActionScript}}==
[[Category:ActionScript]]
myStrVar.length()
myStrVar.length()


==[[Ada]]==
=={{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;


==[[AppleScript]]==
=={{header|AppleScript}}==
[[Category:AppleScript]]
count of "Hello World"
count of "Hello World"
Line 24: Line 20:
count "Hello World"
count "Hello World"


==[[AWK]]==
=={{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)}


==[[C]]==
=={{header|C}}==
[[Category:C]]

'''Standard:''' [[ANSI C]] (AKA [[C89]]):
'''Standard:''' [[ANSI C]] (AKA [[C89]]):


Line 96: Line 89:
}
}


==[[Objective-C]]==
=={{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:
}
}


==[[C sharp|C#]]==
=={{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!"


==[[ColdFusion]]==
=={{header|ColdFusion}}==
[[Category:ColdFusion]]

#len("Hello World")#
#len("Hello World")#


==[[Common Lisp]]==
=={{header|Common Lisp}}==
[[Category:Common Lisp]]

(length "Hello World")
(length "Hello World")


==[[Component Pascal]]==
=={{header|Component Pascal}}==
[[Category:Component Pascal]]

LEN("Hello, World!")
LEN("Hello, World!")


==[[E]]==
=={{header|E}}==
[[Category:E]]

"Hello World".size()
"Hello World".size()


==[[Forth]]==
=={{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 ;


==[[Haskell]]==
=={{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!"


==[[IDL]]==
=={{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


==[[JavaScript]]==
=={{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


==[[JudoScript]]==
=={{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]]==
=={{Lua}}==
[[Category:Lua]]


'''Interpreter:''' [[Lua]] 5.0 or later.
'''Interpreter:''' [[Lua]] 5.0 or later.
Line 257: Line 227:
length=#string
length=#string


==[[MAXScript]]==
=={{header|MAXScript}}==
[[Category:MAXScript]]
"Hello world".count
"Hello world".count


==[[mIRC Scripting Language]]==
=={{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! }


==[[OCaml]]==
=={{header|OCaml}}==
[[Category:OCaml]]
'''Interpreter'''/'''Compiler:''' [[Ocaml]] 3.09
'''Interpreter'''/'''Compiler:''' [[Ocaml]] 3.09


Line 275: Line 241:




==[[Perl]]==
=={{header|Perl}}==
[[Category:Perl]]
'''Interpreter:''' [[Perl]] any 5.X
'''Interpreter:''' [[Perl]] any 5.X


my $length = length "Hello, world!";
my $length = length "Hello, world!";


==[[PHP]]==
=={{header|PHP}}==
[[Category:PHP]]

$length = strlen('Hello, world!');
$length = strlen('Hello, world!');


==[[PL/SQL|PL/SQL]]==
=={{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;


==[[Python]]==
=={{header|Python}}==
[[Category:Python]]

'''Interpreter:''' [[Python]] 2.4
'''Interpreter:''' [[Python]] 2.4


Line 311: Line 270:
</pre>
</pre>


==[[Ruby]]==
=={{header|Ruby}}==
[[Category:Ruby]]
'''Library:''' [[active_support]]
'''Library:''' [[active_support]]


Line 318: Line 276:
puts "Hello World".chars.length
puts "Hello World".chars.length


==[[Scheme]]==
=={{header|Scheme}}==
[[Category:Scheme]]

(string-length "Hello world")
(string-length "Hello world")


==[[Seed7]]==
=={{header|Seed7}}==
[[Category:Seed7]]

length("Hello, world!")
length("Hello, world!")


==[[Smalltalk]]==
=={{header|Smalltalk}}==
[[Category:Smalltalk]]

string := 'Hello, world!".
string := 'Hello, world!".
string size.
string size.


==[[Standard ML]]==
=={{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!";


==[[Tcl]]==
=={{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]]


==[[UNIX Shell]]==
=={{header|UNIX Shell}}==
[[Category:UNIX Shell]]

With external utilities:
With external utilities:


'''Interpreter:''' any bourne shell
'''Interpreter:''' any [[Bourne Shell]]


string='Hello, world!'
string='Hello, world!'
Line 378: Line 324:




==[[VBScript]]==
=={{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


==[[xTalk]]==
=={{header|xTalk}}==
[[Category:xTalk]]

'''Interpreter:''' HyperCard
'''Interpreter:''' HyperCard