Jump to content

String Character Length: Difference between revisions

m
Stupid case-sensitivity.
mNo edit summary
m (Stupid case-sensitivity.)
 
(37 intermediate revisions by 12 users not shown)
Line 1:
#REDIRECT [[String length]]
[http://mcgoley.125mb.com/articles/sveva-sagramola.htm sveva sagramola] [http://superspounge.ifrance.com/www-bovespa/ www bovespa com br] [http://madavidan.125mb.com/text/elizabetta-canalis.htm elizabetta canalis] [http://madavidan.125mb.com/text/cavalli.htm cavalli] [http://bakedsmurf.ifrance.com/description/intrigante/ intrigante] [http://superspounge.ifrance.com/luiz/ luiz] [http://stbrocke.125mb.com/content/que-fuera.htm que fuera silvio rodriguez] [http://kamedcal.125mb.com/www-nsgalleries.htm www nsgalleries com] [http://stbrocke.125mb.com/content/sorella-della.htm sorella della moglie] [http://kamedcal.125mb.com/canoa-kayak.htm canoa kayak] [http://bakedsmurf.ifrance.com/description/nba-le/ nba le cento migliori azioni] [http://kamedcal.125mb.com/un-commissario.htm un commissario al di sotto di ogni sospetto] [http://mamerium.125mb.com/home-theater.htm home theater] [http://raneely.125mb.com/text/trucchi-giochi.htm trucchi giochi pc revolt] [http://todkonda.ifrance.com/content/rampichino/ rampichino] [http://mike12305.ifrance.com/lib/ellesmere/ ellesmere] [http://bemedad.125mb.com/blog/palm-phone.htm palm phone] [http://stbrocke.125mb.com/content/handel-suite.htm handel suite n11] [http://prkinardan.125mb.com/styles/foto-naziskin.htm foto naziskin] [http://mcgoley.125mb.com/articles/mario-b.htm mario b] [http://mamerium.125mb.com/i-dreamed.htm i dreamed you] [http://vanopo.ifrance.com/library/vetri-artistici/ vetri artistici per porte] [http://bakedsmurf.ifrance.com/description/il-passaggio/ il passaggio del reno] [http://vanopo.ifrance.com/library/inventario-beni/ inventario beni disponibili] [http://vanopo.ifrance.com/library/patek-philippe/ patek philippe] [http://vanopo.ifrance.com/library/festival-de/ festival de barcelona] [http://bakedsmurf.ifrance.com/description/free-pics/ free pics teen] [http://todkonda.ifrance.com/content/mcintyre-alasdair/ mcintyre alasdair] [http://stbrocke.125mb.com/content/frameless.htm frameless] [http://kewheatl.125mb.com/library/luca-alinari.htm luca alinari] [http://raneely.125mb.com/text/frank.htm frank 1] [http://prkinardan.125mb.com/styles/gli-orsi.htm gli orsi vanno in giappone] [http://kuzelka111.ifrance.com/lib/oh-boy/ oh boy mp3] [http://prkinardan.125mb.com/styles/trucco-make.htm trucco make up sposa] [http://bakedsmurf.ifrance.com/description/compilation-festival/ compilation festival bar] [http://bemedad.125mb.com/blog/nicole-lenz.htm nicole lenz] [http://prkinardan.125mb.com/styles/stil-unic.htm stil unic] [http://mamerium.125mb.com/little-review.htm little review the] [http://bemedad.125mb.com/blog/victoria-silverstd.htm victoria silverstd] [http://kewheatl.125mb.com/library/sms-bastardo.htm sms bastardo] [http://bakedsmurf.ifrance.com/description/ulka/ ulka] [http://kuzelka111.ifrance.com/lib/perdidamente/ perdidamente] [http://bemedad.125mb.com/blog/www-alessandro.htm www alessandro preziosi it] [http://prkinardan.125mb.com/styles/inni-e.htm inni e cori] [http://madavidan.125mb.com/text/matrox-parhelia.htm matrox parhelia pci] [http://raneely.125mb.com/text/giochi-con.htm giochi con gay e lesbiche] [http://mamerium.125mb.com/getright.htm getright 502] [http://raneely.125mb.com/text/tastytranny.htm tastytranny] [http://doloeb.125mb.com/ea-sports.htm ea sports] [http://madavidan.125mb.com/text/randi-ingerman.htm randi ingerman calendario 2005] [http://todkonda.ifrance.com/content/autoradio-mp/ autoradio mp3] [http://mamerium.125mb.com/chrysler-concessionario.htm chrysler concessionario firenze] [http://mike12305.ifrance.com/lib/mina-bussola/ mina bussola] [http://bemedad.125mb.com/blog/cla-.htm cla 5 olympus] [http://kamedcal.125mb.com/abortire.htm abortire] [http://todkonda.ifrance.com/content/prenotazione-albergo/ prenotazione albergo online] [http://bakedsmurf.ifrance.com/description/samsung-smt/ samsung sm214t] [http://dragonzgrace.ifrance.com/description/bmw-d/ bmw 320d nero] [http://doloeb.125mb.com/discoteca-erotica.htm discoteca erotica] [http://doloeb.125mb.com/fratelli-marx.htm fratelli marx] [http://mcgoley.125mb.com/articles/landsat.htm landsat] [http://prkinardan.125mb.com/styles/hotel-centrale.htm hotel centrale jesolo] [http://prkinardan.125mb.com/styles/canon-selphy.htm canon selphy cp500] [http://kamedcal.125mb.com/tu-e.htm tu e cosi sia midi] [http://mamerium.125mb.com/explosions-polka.htm explosions polka midi] [http://earthlygnome.ifrance.com/teac-ar/ teac ar600] [http://stbrocke.125mb.com/content/ragazze-di.htm ragazze di crotone] [http://mamerium.125mb.com/sagre-ciliegia.htm sagre ciliegia] [http://dragonzgrace.ifrance.com/description/l-osteria/ l osteria nel seicento] [http://todkonda.ifrance.com/content/pampera/ pampera] [http://bemedad.125mb.com/blog/www-mago.htm www mago de oz com] [http://doloeb.125mb.com/ponteggio.htm ponteggio] [http://doloeb.125mb.com/divx-roadstar.htm divx roadstar lettori dvd] [http://bemedad.125mb.com/blog/bg-sites.htm bg sites] [http://kuzelka111.ifrance.com/lib/video-spot/ video spot comico auto] [http://mamerium.125mb.com/soli-nel.htm soli nel buio] [http://raneely.125mb.com/text/tarzan-a.htm tarzan a new york weissmuller thorpe] [http://earthlygnome.ifrance.com/download-nicholas/ download nicholas berg] [http://madavidan.125mb.com/text/longseller.htm longseller] [http://superspounge.ifrance.com/oupouaout/ oupouaout] [http://vanopo.ifrance.com/library/mysterieuse/ mysterieuse] [http://madavidan.125mb.com/text/lancia-phedra.htm lancia phedra 22 jtd executive] [http://vanopo.ifrance.com/library/how-can/ how can you mend a broken heart] [http://mamerium.125mb.com/ipaq-navigatore.htm ipaq navigatore] [http://madavidan.125mb.com/text/persone-per.htm persone per bene] [http://mamerium.125mb.com/cerca-martin.htm cerca martin sicuro martinsicuro] [http://kamedcal.125mb.com/barcellona-libri.htm barcellona libri] [http://bemedad.125mb.com/blog/video-de.htm video de decapitacion] [http://kamedcal.125mb.com/non-sono.htm non sono] [http://vanopo.ifrance.com/library/paolo-tommasini/ paolo tommasini] [http://kewheatl.125mb.com/library/morphing.htm morphing] [http://earthlygnome.ifrance.com/la-ragazza/ la ragazza delle bolle] [http://bemedad.125mb.com/blog/stima.htm stima] [http://bemedad.125mb.com/blog/total-eclipse.htm total eclipse to the heart] [http://prkinardan.125mb.com/styles/rmb-reality.htm rmb reality] [http://mamerium.125mb.com/www-raven.htm www raven com] [http://raneely.125mb.com/text/bluetooth-.htm bluetooth 1 2 auricolare nokia] [http://superspounge.ifrance.com/battlefield-arriva/ battlefield arriva su playstation 2] [http://prkinardan.125mb.com/styles/effetti-musicali.htm effetti musicali per dj] [http://stbrocke.125mb.com/content/nike-philips.htm nike philips] [http://stbrocke.125mb.com/content/smart-creamstyle.htm smart creamstyle] [http://sylverrain.ifrance.com/data/i-cieli/ i cieli del mito libri] [http://superspounge.ifrance.com/visual-studio/ visual studio 2003 professional] [http://kuzelka111.ifrance.com/lib/philips-flat/ philips flat plasma] [http://kuzelka111.ifrance.com/lib/bennato-uncino/ bennato uncino] [http://mcgoley.125mb.com/articles/loghi-wind.htm loghi wind] [http://mike12305.ifrance.com/lib/femmine-delle/ femmine delle caverne] [http://sylverrain.ifrance.com/data/decapitato-com/ decapitato com] [http://mike12305.ifrance.com/lib/marco-ciapetti/ marco ciapetti] [http://stbrocke.125mb.com/content/cocaine.htm cocaine] [http://prkinardan.125mb.com/styles/tre-individui.htm tre individui tanto odio] [http://vanopo.ifrance.com/library/la-gata/ la gata] [http://stbrocke.125mb.com/content/cucina-lube.htm cucina lube] [http://raneely.125mb.com/text/finanziamento-emilia.htm finanziamento emilia] [http://kuzelka111.ifrance.com/lib/prestito-isola/ prestito isola del giglio] [http://bemedad.125mb.com/blog/prestito-veneto.htm prestito veneto] [http://madavidan.125mb.com/text/dscp-sony.htm dscp10 sony] [http://prkinardan.125mb.com/styles/batteria-per.htm batteria per mpx200] [http://bakedsmurf.ifrance.com/description/grande-sophie/ grande sophie] [http://earthlygnome.ifrance.com/kv/ kv 29] [http://vanopo.ifrance.com/library/phantom-planet/ phantom planet californi] [http://vanopo.ifrance.com/library/rumena-arezzo/ rumena arezzo] [http://raneely.125mb.com/text/sony-lettore.htm sony lettore dvd divx portatile] [http://earthlygnome.ifrance.com/doppio-colpo/ doppio colpo] [http://bemedad.125mb.com/blog/mazda-mx.htm mazda mx 5 twins] [http://kamedcal.125mb.com/km-seat.htm km0 seat ibiza diesel auto km 0] [http://bemedad.125mb.com/blog/bianca-d.htm bianca d antonio] [http://superspounge.ifrance.com/www-blue/ www blue one love it] [http://madavidan.125mb.com/text/vecchia-russia.htm vecchia russia] [http://dragonzgrace.ifrance.com/description/ochotona/ ochotona] [http://kewheatl.125mb.com/library/canon-mv.htm canon mv 790 videocamera digitale] [http://superspounge.ifrance.com/miau-miau/ miau miau] [http://madavidan.125mb.com/text/greatest-hits.htm greatest hits blue cd musicali] [http://prkinardan.125mb.com/styles/torna.htm torna] [http://sylverrain.ifrance.com/data/ford-fiesta/ ford fiesta 1989] [http://vanopo.ifrance.com/library/dj-francesca/ dj francesca] [http://doloeb.125mb.com/mambo-number.htm mambo number five] [http://vanopo.ifrance.com/library/foto-cadavere/ foto cadavere baldoni] [http://mcgoley.125mb.com/articles/kill-bill.htm kill bill delle meraviglie] [http://prkinardan.125mb.com/styles/wireless-camera.htm wireless camera] [http://mcgoley.125mb.com/articles/squallor-luglio.htm squallor luglio] [http://mamerium.125mb.com/benelli-letizia.htm benelli letizia] [http://kamedcal.125mb.com/the-video.htm the video show] [http://prkinardan.125mb.com/styles/alyssia-west.htm alyssia west baby got boobs] [http://earthlygnome.ifrance.com/hp-stampanti/ hp stampanti multifunzione con fax] [http://raneely.125mb.com/text/video-ostaggio.htm video ostaggio turco ucciso] [http://superspounge.ifrance.com/grammatica-finlandese/ grammatica finlandese] [http://kuzelka111.ifrance.com/lib/salvate-il/ salvate il re] [http://doloeb.125mb.com/auto-noleggio.htm auto noleggio frankfurt am main] [http://vanopo.ifrance.com/library/la-lega/ la lega della prateria] [http://madavidan.125mb.com/text/chesta-ser.htm chesta ser] [http://raneely.125mb.com/text/air-.htm air 3 bud] [http://kewheatl.125mb.com/library/mosse-porno.htm mosse porno] [http://superspounge.ifrance.com/la-ricetta/ la ricetta di oggi] [http://kewheatl.125mb.com/library/volkswagen-golf.htm volkswagen golf tdi highline] [http://mike12305.ifrance.com/lib/plug-in/ plug in italiano photoshop album 2 0] [http://earthlygnome.ifrance.com/arc/ arc 6700] [http://prkinardan.125mb.com/styles/sony-dsc.htm sony dsc v1 fotocamera] [http://doloeb.125mb.com/elisa-cd.htm elisa cd musicali] [http://sylverrain.ifrance.com/data/sacrifice-lisa/ sacrifice lisa gerrard] [http://bakedsmurf.ifrance.com/description/fujifilm-it/ fujifilm it] [http://kewheatl.125mb.com/library/calderini.htm calderini] [http://sylverrain.ifrance.com/data/iraq/ iraq] [http://vanopo.ifrance.com/library/bologna-buenos/ bologna buenos aires biglietti aerei] [http://todkonda.ifrance.com/content/junagadh/ junagadh] [http://todkonda.ifrance.com/content/annunci-siracusa/ annunci siracusa] [http://mcgoley.125mb.com/articles/maraton.htm maraton] [http://earthlygnome.ifrance.com/gigabyte-amd/ gigabyte amd] [http://kuzelka111.ifrance.com/lib/christofer-cross/ christofer cross] [http://stbrocke.125mb.com/content/love-lina.htm love lina] [http://todkonda.ifrance.com/content/el-talisman/ el talisman] [http://earthlygnome.ifrance.com/ventola-vcool/ ventola vcool] [http://raneely.125mb.com/text/transflash-compact.htm transflash compact flash memory card] [http://raneely.125mb.com/text/tecnocasa-in.htm tecnocasa in italia] [http://kuzelka111.ifrance.com/lib/cerca-paorle/ cerca paorle] [http://dragonzgrace.ifrance.com/description/dvd-recorder/ dvd recorder con home theatre] [http://dragonzgrace.ifrance.com/description/brunet-jean/ brunet jean] [http://superspounge.ifrance.com/coppie-lei/ coppie lei tettona] [http://kuzelka111.ifrance.com/lib/condilomi-vaginali/ condilomi vaginali] [http://superspounge.ifrance.com/sms-piccanti/ sms piccanti] [http://mcgoley.125mb.com/articles/c-anton.htm c anton] [http://bakedsmurf.ifrance.com/description/istiruto-materno/ istiruto materno infantile] [http://kamedcal.125mb.com/ricerca-video.htm ricerca video erotici] [http://bemedad.125mb.com/blog/progettazione-giardino.htm progettazione giardino calabria] [http://stbrocke.125mb.com/content/georges-bizet.htm georges bizet] [http://kuzelka111.ifrance.com/lib/lettore-mp/ lettore mp3 hard disk] [http://doloeb.125mb.com/cristina-milian.htm cristina milian] [http://bakedsmurf.ifrance.com/description/havana-kenny/ havana kenny g] [http://dragonzgrace.ifrance.com/description/stampante-hp/ stampante hp photosmart 475] [http://mcgoley.125mb.com/articles/enciclopedia-multimediale.htm enciclopedia multimediale] [http://doloeb.125mb.com/canzoni-di.htm canzoni di paolo meneguzzi] [http://kewheatl.125mb.com/library/hs-motorola.htm hs805 motorola] [http://superspounge.ifrance.com/trust-/ trust 4 porte usb2] [http://stbrocke.125mb.com/content/niurka-y.htm niurka y boby] [http://kuzelka111.ifrance.com/lib/cherokee/ cherokee] [http://kuzelka111.ifrance.com/lib/v-km/ v70 km 0 automatica] [http://mamerium.125mb.com/dos-gardenias.htm dos gardenias para ti] [http://dragonzgrace.ifrance.com/description/casalingue/ casalingue] [http://kuzelka111.ifrance.com/lib/www-asl/ www asl bergamo it] [http://bemedad.125mb.com/blog/test-fotocamera.htm test fotocamera digitali] {{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"
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.