String Character Length: Difference between revisions

From Rosetta Code
Content deleted Content added
mNo edit summary
m Stupid case-sensitivity.
 
(52 intermediate revisions by 14 users not shown)
Line 1:
#REDIRECT [[String length]]
[http://mouse-zae.110mb.com/lcd-panasonic.htm lcd panasonic] [http://trene-von-anty.110mb.com/description/alien-psp.htm alien psp] [http://stitchesnglue.110mb.com/reflection-mulan.htm reflection mulan] [http://blue-olusha.110mb.com/library/goodrem/ goodrem] [http://stitchesnglue.110mb.com/costume-arabo.htm costume arabo] [http://olikka.110mb.com/library/benjamin-anastas.htm benjamin anastas] [http://sister-sunshine.110mb.com/html/pena-morte/ pena morte] [http://mouse-zae.110mb.com/nokia-.htm nokia 5140 red] [http://lazythoughts.110mb.com/lib/panasonic-lumix/ panasonic lumix fz20] [http://funk-mastah-ion.110mb.com/data/willy-il.htm willy il coyote] [http://sister-sunshine.110mb.com/html/driver-modem/ driver modem usb motorola] [http://forever-your.110mb.com/data/gark.htm gark] [http://slavkamolot.110mb.com/library/salsa-adolecentes/ salsa adolecentes] [http://sister-sunshine.110mb.com/html/yu-ghi/ yu ghi ho] [http://slavkamolot.110mb.com/library/nokia-image/ nokia image viewer] [http://nationavce.110mb.com/view/julianne-moore.htm julianne moore] [http://nationavce.110mb.com/view/giuseppe-verdi.htm giuseppe verdi macbeth] [http://mouse-zae.110mb.com/epson-dlq.htm epson dlq 3000] [http://lazythoughts.110mb.com/lib/miedo-pepe/ miedo pepe aguilar] [http://blue-olusha.110mb.com/library/sommergibile/ sommergibile] [http://blue-olusha.110mb.com/library/mandolina/ mandolina] [http://blue-olusha.110mb.com/library/punto-/ punto 1 9 hgt] [http://dialed.110mb.com/small/film-divx/ film divx scaricare] [http://book-wench.110mb.com/text/deejay-provenzano/ deejay provenzano] [http://nationavce.110mb.com/view/www-xpirin.htm www xpirin com] [http://mouse-zae.110mb.com/delphine-pacific.htm delphine pacific] [http://book-wench.110mb.com/text/powerpoint-free/ powerpoint free download] [http://sneezingpops.110mb.com/a-s/ a s p h i it] [http://sister-sunshine.110mb.com/html/biglietti-aerei/ biglietti aerei londra] [http://trouble166.110mb.com/uisp.htm uisp] [http://mouse-zae.110mb.com/mezz-ira.htm mezz ira] [http://gekijuls.110mb.com/las-mejore/ las mejore pistas] [http://blue-olusha.110mb.com/library/climatizzatore-delonghi/ climatizzatore delonghi 12000 btu] [http://ultra-creator.110mb.com/articles/tv-key.htm tv key] [http://stitchesnglue.110mb.com/busty-milf.htm busty milf] [http://stitchesnglue.110mb.com/hardporno.htm hardporno] [http://stitchesnglue.110mb.com/promo-brasil.htm promo brasil] [http://funk-mastah-ion.110mb.com/data/musica-italiana.htm musica italiana audio] [http://book-wench.110mb.com/text/olympus-fe/ olympus fe100] [http://lazythoughts.110mb.com/lib/guinnes-dei/ guinnes dei primati] [http://yeeden.110mb.com/data/lg-/ lg frigorifero] [http://dialed.110mb.com/small/philips/ philips 30] [http://mouse-zae.110mb.com/russians.htm russians] [http://forever-your.110mb.com/data/intel-p.htm intel p4 830] [http://blue-olusha.110mb.com/library/usb-infrarossi/ usb infrarossi irda] [http://slavkamolot.110mb.com/library/calcio-lazio/ calcio lazio] [http://blue-olusha.110mb.com/library/polar-s/ polar s610] [http://forever-your.110mb.com/data/www-.htm www 190 it] [http://ultra-creator.110mb.com/articles/whe-are.htm whe are family] [http://book-wench.110mb.com/text/e-i/ e720 i] [http://blue-olusha.110mb.com/library/ing-elettronico/ ing elettronico prototipi (regione toscana firenze provincia)] [http://dialed.110mb.com/small/drieu-la/ drieu la rochelle pierre] [http://funk-mastah-ion.110mb.com/data/baila-sexy.htm baila sexy thing zucchero] [http://lazythoughts.110mb.com/lib/sigla-cartone/ sigla cartone animato] [http://sister-sunshine.110mb.com/html/leyes-laborales/ leyes laborales en panama] [http://sneezingpops.110mb.com/jangjin/ jangjin] [http://sister-sunshine.110mb.com/html/video-poker/ video poker porno gratis] [http://sneezingpops.110mb.com/handicappati/ handicappati] [http://forever-your.110mb.com/data/karena.htm karena] [http://book-wench.110mb.com/text/www-pornostar/ www pornostar it] [http://book-wench.110mb.com/text/www-citta/ www citta di napoli it] [http://lazythoughts.110mb.com/lib/poro-video/ poro video video] [http://sister-sunshine.110mb.com/html/kit-ricevitore/ kit ricevitore digitale] [http://gekijuls.110mb.com/globalsat-bt/ globalsat bt338 bluetooth gps] [http://lazythoughts.110mb.com/lib/annunci-con/ annunci con foto gay x gay] [http://book-wench.110mb.com/text/dj-tommy/ dj tommy vee serenissima] [http://sister-sunshine.110mb.com/html/jack-lemmon/ jack lemmon] [http://ultra-creator.110mb.com/articles/www-chef.htm www chef di cucina it] [http://trene-von-anty.110mb.com/description/cuneyt-ozgur.htm cuneyt ozgur] [http://funk-mastah-ion.110mb.com/data/amici-miei.htm amici miei atto] [http://some-omeelse.110mb.com/data/moto-autodromo.htm moto autodromo del mugello] [http://slavkamolot.110mb.com/library/kodak-stampanti/ kodak stampanti a sublimazione] [http://unremig.110mb.com/simply-scripts/ simply scripts] [http://sneezingpops.110mb.com/tutto-reflex/ tutto reflex fotocamere] [http://sneezingpops.110mb.com/studio-emmevi/ studio emmevi] [http://stitchesnglue.110mb.com/coppie-escort.htm coppie escort] [http://slavkamolot.110mb.com/library/coppia-siciliana/ coppia siciliana] [http://sneezingpops.110mb.com/bernini-architetto/ bernini architetto] [http://sister-sunshine.110mb.com/html/franceso-renga/ franceso renga] [http://nationavce.110mb.com/view/formica-di.htm formica di montecristo] [http://book-wench.110mb.com/text/gold-four/ gold four] [http://blue-olusha.110mb.com/library/holliday-in/ holliday in] [http://dialed.110mb.com/small/lettore-cd/ lettore cd portatile con radio] [http://forever-your.110mb.com/data/palmare-con.htm palmare con ricevitore gps integrato] [http://unremig.110mb.com/elenco-abbonati/ elenco abbonati telefonici] [http://some-omeelse.110mb.com/data/video-iracheni.htm video iracheni] [http://sneezingpops.110mb.com/joseph-farrel/ joseph farrel] [http://trene-von-anty.110mb.com/description/camping-gas.htm camping gas] [http://stitchesnglue.110mb.com/baila-gigi.htm baila gigi d alessio] [http://forever-your.110mb.com/data/disco.htm disco] [http://forever-your.110mb.com/data/farmaceutica.htm farmaceutica] [http://sister-sunshine.110mb.com/html/auto-golf/ auto golf iv] [http://olikka.110mb.com/library/fotocamere-olympus.htm fotocamere olympus] [http://mouse-zae.110mb.com/hamlet-hd.htm hamlet hd 250] [http://sneezingpops.110mb.com/gallipoli-foto/ gallipoli foto mare] [http://unremig.110mb.com/knotcard/ knotcard] [http://blue-olusha.110mb.com/library/agrumo/ agrumo] [http://mouse-zae.110mb.com/biglietti-visita.htm biglietti visita] [http://unremig.110mb.com/dane-clemence/ dane clemence] [http://forever-your.110mb.com/data/www-architettura.htm www architettura unipa it] [http://book-wench.110mb.com/text/online-i/ online i siti di electronic arts italia] [http://stitchesnglue.110mb.com/berlino-est.htm berlino est passaporto falso] [http://sneezingpops.110mb.com/schede-grafiche/ schede grafiche nvidia] [http://dialed.110mb.com/small/mnarani/ mnarani] [http://stitchesnglue.110mb.com/solo-foto.htm solo foto piede] [http://stitchesnglue.110mb.com/cyborg-mares.htm cyborg mares] [http://blue-olusha.110mb.com/library/marketing-tesi/ marketing tesi] [http://yeeden.110mb.com/data/l-extraterrestre/ l extraterrestre] [http://unremig.110mb.com/raubling/ raubling] [http://forever-your.110mb.com/data/werdau.htm werdau] [http://forever-your.110mb.com/data/ustica-villagi.htm ustica villagi] [http://dialed.110mb.com/small/trans-nero/ trans nero] [http://trouble166.110mb.com/hdd-usb.htm hdd usb ps2] [http://book-wench.110mb.com/text/valutazione-auto/ valutazione auto] [http://gekijuls.110mb.com/broadside/ broadside] [http://dialed.110mb.com/small/taichi/ taichi] [http://nationavce.110mb.com/view/giochi-dei.htm giochi dei percorsi] [http://mouse-zae.110mb.com/convertitore-.htm convertitore 3 gp] [http://nationavce.110mb.com/view/www-shesexy.htm www shesexy com] [http://forever-your.110mb.com/data/nokia-red.htm nokia red] [http://stitchesnglue.110mb.com/mivar-m.htm mivar m51 silver] [http://ultra-creator.110mb.com/articles/protocollo-di.htm protocollo di kyoto] [http://forever-your.110mb.com/data/jbl-ti.htm jbl ti 250] [http://yeeden.110mb.com/data/testo-di/ testo di heaven di brian adams] [http://unremig.110mb.com/pianeta-b/ pianeta b] [http://some-omeelse.110mb.com/data/videocamere-usb.htm videocamere usb] [http://funk-mastah-ion.110mb.com/data/protezione-pc.htm protezione pc] [http://funk-mastah-ion.110mb.com/data/gigabyte-kt.htm gigabyte kt600] [http://trene-von-anty.110mb.com/description/maizuru.htm maizuru] [http://some-omeelse.110mb.com/data/roma-bogota.htm roma bogota biglietti aerei] [http://some-omeelse.110mb.com/data/ordini-professionali.htm ordini professionali] [http://olikka.110mb.com/library/dammi-solo.htm dammi solo] [http://lazythoughts.110mb.com/lib/videoregistratore-vhs/ videoregistratore vhs panasonic] [http://forever-your.110mb.com/data/le-keywords.htm le keywords] [http://trouble166.110mb.com/odo.htm odo] [http://some-omeelse.110mb.com/data/ti-si.htm ti si moja prva ljubav] [http://mouse-zae.110mb.com/convertitore-valuta.htm convertitore valuta] [http://trouble166.110mb.com/dvd-.htm dvd r 4 x] [http://nationavce.110mb.com/view/lcd-.htm lcd 32 aquos] [http://yeeden.110mb.com/data/sandi/ sandi] [http://gekijuls.110mb.com/natalizi/ natalizi] [http://sneezingpops.110mb.com/puma-bimbo/ puma bimbo] [http://sister-sunshine.110mb.com/html/punt-e/ punt e mes] [http://blue-olusha.110mb.com/library/sado-maso/ sado maso bsx] [http://forever-your.110mb.com/data/minaccie-italia.htm minaccie italia] [http://mouse-zae.110mb.com/mp.htm mp3 60] [http://nationavce.110mb.com/view/vignette-sulle.htm vignette sulle vacanze] [http://sister-sunshine.110mb.com/html/patricia-araujo/ patricia araujo] [http://funk-mastah-ion.110mb.com/data/sopra-e.htm sopra e sotto il letto] [http://gekijuls.110mb.com/epr/ epr] [http://forever-your.110mb.com/data/cavo-hard.htm cavo hard disck] [http://some-omeelse.110mb.com/data/grosso-pene.htm grosso pene] [http://lazythoughts.110mb.com/lib/prenotazione-hotel/ prenotazione hotel ferrara] [http://lazythoughts.110mb.com/lib/dieta-/ dieta 1800 caloria] [http://ultra-creator.110mb.com/articles/rascel-marine.htm rascel marine] [http://ultra-creator.110mb.com/articles/collistar.htm collistar] [http://stitchesnglue.110mb.com/lettore-schede.htm lettore schede mmc] [http://sister-sunshine.110mb.com/html/esproprio/ esproprio] [http://trene-von-anty.110mb.com/description/kraftwerk-cd.htm kraftwerk cd] [http://yeeden.110mb.com/data/ghosts-and/ ghosts and goblins] [http://lazythoughts.110mb.com/lib/lauda-italia/ lauda italia] [http://blue-olusha.110mb.com/library/ericsson/ ericsson 300] [http://trouble166.110mb.com/foto-di.htm foto di scooter] [http://lazythoughts.110mb.com/lib/yahho-com/ yahho com mx] [http://slavkamolot.110mb.com/library/wwwgoogle-come/ wwwgoogle come com] [http://yeeden.110mb.com/data/landing-gear/ landing gear] [http://mouse-zae.110mb.com/sfondi-colorati.htm sfondi colorati x nokia7210] [http://dialed.110mb.com/small/x-tv/ x tv yakusoku download] [http://nationavce.110mb.com/view/kessler-alice.htm kessler alice ellen] [http://sister-sunshine.110mb.com/html/tv-/ tv 26 sharp] [http://dialed.110mb.com/small/taglio-laser/ taglio laser produzione] [http://funk-mastah-ion.110mb.com/data/ritorno-a.htm ritorno a eden] [http://dialed.110mb.com/small/nelly-furtado/ nelly furtado euro2004] [http://sneezingpops.110mb.com/tema-svolto/ tema svolto pedagogia] [http://dialed.110mb.com/small/quattro-giorni/ quattro giorni a settembre] [http://stitchesnglue.110mb.com/f-kit.htm f kit i don t want you back] [http://stitchesnglue.110mb.com/cuffia-dj.htm cuffia dj] [http://forever-your.110mb.com/data/pavimenti-discount.htm pavimenti discount] [http://blue-olusha.110mb.com/library/greatest-love/ greatest love of all] [http://lazythoughts.110mb.com/lib/l-amore/ l amore e nell aria stasera] [http://slavkamolot.110mb.com/library/cantico/ cantico] [http://nationavce.110mb.com/view/nightmare-.htm nightmare 3 i guerrieri del sogno] [http://unremig.110mb.com/i-culi/ i culi piu belli] [http://mouse-zae.110mb.com/mercedes-v.htm mercedes v 220 cdi] [http://forever-your.110mb.com/data/finanziamento-cannes.htm finanziamento cannes] [http://trene-von-anty.110mb.com/description/motorola-nero.htm motorola nero] [http://forever-your.110mb.com/data/le-mark.htm le mark latina] [http://trene-von-anty.110mb.com/description/nanni.htm nanni] [http://unremig.110mb.com/loewe/ loewe 37] [http://nationavce.110mb.com/view/scuoladell-infanzia.htm scuoladell infanzia] [http://trene-von-anty.110mb.com/description/barbara-guglielmi.htm barbara guglielmi] [http://book-wench.110mb.com/text/mahj/ mahj] [http://stitchesnglue.110mb.com/samsung-lettore.htm samsung lettore mp3] [http://sneezingpops.110mb.com/huichol/ huichol] [http://stitchesnglue.110mb.com/la-donna.htm la donna piu grassa del mondo] [http://yeeden.110mb.com/data/andando-conmigo/ andando conmigo] [http://slavkamolot.110mb.com/library/san-donato/ san donato milanese] [http://stitchesnglue.110mb.com/geforce-le.htm geforce 6800le agp] [http://blue-olusha.110mb.com/library/john-lee/ john lee hooker the definitive collection] [http://mouse-zae.110mb.com/casse-home.htm casse home cinema] {{task}}
{{Template:split-review}}
In this task, the goal is to find the <em>character</em> length of a string. This means encodings like [[UTF-8]] need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters.
 
For byte length, see [[String Byte Length]].
 
==[[ActionScript]]==
[[Category:ActionScript]]
myStrVar.length()
 
==[[Ada]]==
[[Category:Ada]]
 
'''Compiler:''' GCC 4.1.2
 
Str : String := "Hello World";
Length : constant Natural := Str'Length;
 
==[[AppleScript]]==
[[Category:AppleScript]]
count of "Hello World"
 
==[[AWK]]==
[[Category:AWK]]
From within any code block:
w=length("Hello, world!") # static string example
x=length("Hello," s " world!") # dynamic string example
y=length($1) # input field example
z=length(s) # variable name example
Ad hoc program from command line:
echo "Hello, world!" | awk '{print length($0)}'
From executable script: (prints for every line arriving on stdin)
#!/usr/bin/awk -f
{print"The length of this line is "length($0)}
 
==[[C]]==
[[Category:C]]
 
'''Standard:''' [[ANSI C]] (AKA [[C89]]):
 
'''Compiler:''' GCC 3.3.3
 
#include <string.h>
int main(void)
{
const char *string = "Hello, world!";
size_t length = strlen(string);
return 0;
}
 
or by hand:
 
int main(void)
{
const char *string = "Hello, world!";
size_t length = 0;
char *p = (char *) string;
while (*p != '\0') length ;
return 0;
}
 
or (for arrays of char only)
 
#include <stdlib.h>
int main(void)
{
char const s[] = "Hello, world!";
size_t length = sizeof s - 1;
return 0;
}
 
For wide character strings (usually Unicode):
 
#include <stdio.h>
#include <wchar.h>
int main(void)
{
wchar_t *s = L"\x304A\x306F\x3088\x3046"; /* Japanese hiragana ohayou */
size_t length;
length = wcslen(s);
printf("Length in characters = %d\n", length);
printf("Length in bytes = %d\n", sizeof(s) * sizeof(wchar_t));
return 0;
}
 
==[[C plus plus|C ]]==
[[Category:C plus plus|C ]]
 
'''Standard:''' [[ISO C plus plus|ISO C ]] (AKA [[C plus plus 98|C 98]]):
 
'''Compiler:''' g 4.0.2
 
#include <string> // note: '''not''' <string.h>
int main()
{
std::string s = "Hello, world!";
// Always in characters == bytes since sizeof(char) == 1
std::string::size_type length = s.length(); // option 1: In Characters/Bytes
std::string::size_type size = s.size(); // option 2: In Characters/Bytes
}
 
For wide character strings:
 
#include <string>
int main()
{
std::wstring s = L"\u304A\u306F\u3088\u3046";
std::wstring::size_type length = s.length();
}
 
==[[C sharp|C#]]==
[[Category:C sharp|C#]]
 
'''Platform:''' [[.NET]]
'''Language Version:''' 1.0
 
string s = "Hello, world!";
int clength = s.Length; // In characters
int blength = System.Text.Encoding.GetBytes(s).length; // In Bytes.
 
==[[Clean]]==
[[Category:Clean]]
 
Clean Strings are unboxed arrays of characters. Characters are always a single byte. The function size returns the number of elements in an array.
 
import StdEnv
strlen :: String -> Int
strlen string = size string
Start = strlen "Hello, world!"
 
==[[ColdFusion]]==
[[Category:ColdFusion]]
 
#len("Hello World")#
 
==[[Common Lisp]]==
[[Category:Common Lisp]]
 
(length "Hello World")
 
==[[Component Pascal]]==
[[Category:Component Pascal]]
 
LEN("Hello, World!")
 
==[[E]]==
[[Category:E]]
 
"Hello World".size()
 
==[[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.)
 
'''Interpreter:''' ANS Forth
 
The following code will count the number of UTF-8 characters in a null-terminated string. It relies on the fact that all bytes of a UTF-8 character except the first have the the binary bit pattern "10xxxxxx".
 
binary
: utf8 ( str -- str )
begin
char
dup c@
11000000 and
10000000 <>
until ;
decimal
: count-utf8 ( zstr -- n )
0
begin
swap dup c@
while
utf8
swap 1
repeat drop ;
 
==[[Haskell]]==
[[Category:Haskell]]
 
'''Interpreter:''' [[GHC | GHCi]] 6.6, [[Hugs]]
 
'''Compiler:''' [[GHC]] 6.6
 
strlen = length "Hello, world!"
 
==[[IDL]]==
[[Category:IDL]]
 
'''Compiler:''' any IDL compiler should do
 
length = strlen("Hello, world!")
 
==[[Java]]==
[[Category:Java]]
 
Java 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.
 
The length method of String objects gives the number of 16-bit values used to encode a string.
String s = "Hello, world!";
int length = s.length();
 
Since Java 1.5, the actual number of characters can be determined by calling the codePointCount method.
String str = "\uD834\uDD2A"; //U 1D12A
int length1 = str.length(); //2
int length2 = str.codePointCount(0, str.length()); //1
 
==[[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 has no built-in way to determine how many characters are in a string. However, if the string only contains commonly used characters, the number of characters will be equal to the number of 16-bit values used to represent the characters.
var str1 = "Hello, world!";
var len1 = str1.length; //13
var str2 = "\uD834\uDD2A"; //U 1D12A represented by a UTF-16 surrogate pair
var len2 = str2.length; //2
 
==[[JudoScript]]==
[[Category:JudoScript]]
 
//Store length of hello world in length and print it
. length = "Hello World".length();
 
==[[Lua]]==
[[Category:Lua]]
 
'''Interpreter:''' [[Lua]] 5.0 or later.
 
string="Hello world"
length=#string
 
==[[mIRC Scripting Language]]==
[[Category:mIRC Scripting Language]]
 
'''Interpreter:''' [[mIRC]]
 
alias stringlength { echo -a Your Name is: $len($$?="Whats your name") letters long! }
 
==[[OCaml]]==
[[Category:OCaml]]
'''Interpreter'''/'''Compiler:''' [[Ocaml]] 3.09
 
String.length "Hello world";;
 
 
==[[Perl]]==
[[Category:Perl]]
'''Interpreter:''' [[Perl]] any 5.X
 
my $length = length "Hello, world!";
 
==[[PHP]]==
[[Category:PHP]]
 
$length = strlen('Hello, world!');
 
==[[PL/SQL|PL/SQL]]==
[[Category:PL/SQL|PL/SQL]]
 
DECLARE
string VARCHAR2( 50 ) := 'Hello, world!';
stringlength NUMBER;
BEGIN
stringlength := length( string );
END;
 
==[[Python]]==
[[Category:Python]]
 
'''Interpreter:''' [[Python]] 2.4
 
length = len("The length of this string will be determined")
 
==[[Ruby]]==
[[Category:Ruby]]
'''Library:''' [[active_support]]
 
require 'active_support'
puts "Hello World".chars.length
 
==[[Scheme]]==
[[Category:Scheme]]
 
(string-length "Hello world")
 
==[[Seed7]]==
[[Category:Seed7]]
 
length("Hello, world!")
 
==[[Smalltalk]]==
[[Category:Smalltalk]]
 
string := 'Hello, world!".
string size.
 
==[[Standard ML]]==
[[Category:Standard ML]]
 
'''Interpreter:''' [[Standard ML of New Jersey | SML/NJ]] 110.60, [[Moscow ML]] 2.01 (January 2004)
 
'''Compiler:''' [[MLton]] 20061107
 
val strlen = size "Hello, world!";
 
==[[Tcl]]==
[[Category:Tcl]]
 
Basic version:
 
string length "Hello, world!"
 
or more elaborately, needs '''Interpreter''' any 8.X. Tested on 8.4.12.
 
fconfigure stdout -encoding utf-8; #So that Unicode string will print correctly
set s1 "hello, world"
set s2 "\u304A\u306F\u3088\u3046"
puts [format "length of \"%s\" in characters is %d" $s1 [string length $s1]]
puts [format "length of \"%s\" in characters is %d" $s2 [string length $s2]]
 
==[[UNIX Shell]]==
[[Category:UNIX Shell]]
 
With external utilities:
 
'''Interpreter:''' any bourne shell
 
string='Hello, world!'
length=`echo -n "$string" | wc -c | tr -dc '0-9'`
echo $length # if you want it printed to the terminal
 
With SUSv3 parameter expansion modifier:
 
'''Interpreter:''' [[Almquist SHell]] (NetBSD 3.0), [[Bourne Again SHell]] 3.2, [[Korn SHell]] (5.2.14 99/07/13.2), [[Z SHell]]
 
string='Hello, world!'
length="${#string}"
echo $length # if you want it printed to the terminal
 
 
==[[VBScript]]==
[[Category:VBScript]]
Len(string|varname)
 
Returns the length of the string|varname
Returns null if string|varname is null
 
==[[xTalk]]==
[[Category:xTalk]]
 
'''Interpreter:''' HyperCard
 
put the length of "Hello World"
 
or
 
put the number of characters in "Hello World"

Latest revision as of 19:31, 19 January 2008

Redirect to: