String Character Length: Difference between revisions
mNo edit summary |
(Undo revision 7913 by Special:Contributions/SdqZt5 (User talk:SdqZt5)) |
||
Line 1: | Line 1: | ||
{{task}} |
|||
[http://banzlees.airsofthost.com/description/lib/intel-p.htm intel p4 pentium 4 3 2 ghz 640 2mb 775] [http://hdurian.airsofthost.com/view/new/canzone-di.htm canzone di vasco rossi] [http://play-station.otrev4ro.info play station silver] [http://remayfuy.airsofthost.com/images/small/nero-burning/ nero burning] [http://frgrossm.airsofthost.com/topic/campi-di/ campi di calcio] [http://rumote.airsofthost.com/lib/immagini-fiabe.htm immagini fiabe] [http://hdurian.airsofthost.com/view/new/franco-devita.htm franco devita] [http://chieu-email.monbrenno.info chieu email contact address] [http://lejenny.airsofthost.com/library/html/il-messicano.htm il messicano] [http://selen-video.monbrenno.info selen video porno] [http://alpaddy.airsofthost.com/img/styles/zampa-di/ zampa di gatto] [http://hdurian.airsofthost.com/view/new/grade-moj.htm grade moj] [http://rosina-cristian.firethro.info rosina cristian] [http://blutengel.otrev4ro.info blutengel] [http://rumote.airsofthost.com/lib/giappone-cose.htm giappone cose fare] [http://banzlees.airsofthost.com/description/lib/suzuki-grand.htm suzuki grand vitara xl 7] [http://www-bellsouth.cleric4u.info www bellsouth com ec] [http://banzlees.airsofthost.com/description/lib/felpe-uomo.htm felpe uomo con cappuccio] [http://lejenny.airsofthost.com/library/html/swan-tour.htm swan tour] [http://remayfuy.airsofthost.com/images/small/masia-giuseppe/ masia giuseppe] [http://e-mule.giantlau.info e mule] [http://crociera-vela.otrev4ro.info crociera vela] [http://banzlees.airsofthost.com/description/lib/beyonce-myself.htm beyonce myself] [http://laortiz.airsofthost.com/view/new/gisell/ gisell] [http://laortiz.airsofthost.com/view/new/omega-seamaster/ omega seamaster apnea] [http://lejenny.airsofthost.com/library/html/io-confesso.htm io confesso] [http://alpaddy.airsofthost.com/img/styles/diesel-uomo/ diesel uomo 28] [http://remayfuy.airsofthost.com/images/small/lombra-nella/ lombra nella notte] [http://dove-vai.giantlau.info dove vai vasco] [http://rumote.airsofthost.com/lib/ove-noci.htm ove noci jedna zena] [http://suavis.giantlau.info suavis] [http://nuova-renault.firethro.info nuova renault modus auto nuove] [http://frgrossm.airsofthost.com/topic/matrixis/ matrixis] [http://laortiz.airsofthost.com/view/new/lettore-di/ lettore di impronte digitali microsoft] [http://frgrossm.airsofthost.com/topic/materasso-lattice/ materasso lattice] [http://alpaddy.airsofthost.com/img/styles/dimm-ddr/ dimm ddr 1gb 333mhz] [http://www-brasile.cleric4u.info www brasile tour it] [http://prior-matthew.otrev4ro.info prior matthew] [http://frgrossm.airsofthost.com/topic/audi-usata/ audi usata milano] [http://splucind.airsofthost.com/content/view/canon-eos/ canon eos 33] [http://alpaddy.airsofthost.com/img/styles/wendi/ wendi] [http://hdurian.airsofthost.com/view/new/breakbeat.htm breakbeat] [http://remayfuy.airsofthost.com/images/small/cori-curva/ cori curva sud milan] [http://vendita-dvd.otrev4ro.info vendita dvd r vergine] [http://banzlees.airsofthost.com/description/lib/nvidia-quadro.htm nvidia quadro 4] [http://hdurian.airsofthost.com/view/new/destiny-child.htm destiny child] [http://laortiz.airsofthost.com/view/new/prisionera-balada/ prisionera balada] [http://alpaddy.airsofthost.com/img/styles/scug/ scug] [http://splucind.airsofthost.com/content/view/schlesien/ schlesien] [http://servizio-autobus.monbrenno.info servizio autobus lecco milano centrale] [http://laortiz.airsofthost.com/view/new/tavolo-legno/ tavolo legno teak] [http://umidificatore-sigari.otrev4ro.info umidificatore sigari] [http://laortiz.airsofthost.com/view/new/web-kat/ web kat gratis] [http://donatella-donatella.firethro.info donatella donatella rettore] [http://colonnine.otrev4ro.info colonnine] [http://hexalot.monbrenno.info hexalot] [http://banzlees.airsofthost.com/description/lib/toshiba-satellite.htm toshiba satellite 2x512] [http://alpaddy.airsofthost.com/img/styles/antivirus-norton/ antivirus norton] [http://delonghi.firethro.info delonghi 220] [http://splucind.airsofthost.com/content/view/stylus-dx/ stylus dx4800] [http://hdurian.airsofthost.com/view/new/cd-cover.htm cd cover archive] [http://laortiz.airsofthost.com/view/new/bruno-lauzi/ bruno lauzi midi free] [http://splucind.airsofthost.com/content/view/giannis/ giannis] [http://remayfuy.airsofthost.com/images/small/mantova-trans/ mantova trans] [http://hdurian.airsofthost.com/view/new/havens-here.htm havens here comes] [http://alpaddy.airsofthost.com/img/styles/torn-apart/ torn apart] [http://laortiz.airsofthost.com/view/new/plugin/ plugin] [http://lejenny.airsofthost.com/library/html/divx-amstrad.htm divx amstrad dvd lettori e] [http://i-don.otrev4ro.info i don t want] [http://remayfuy.airsofthost.com/images/small/herbie-un/ herbie un maggiolino tutto] [http://alpaddy.airsofthost.com/img/styles/interrogazione-client/ interrogazione client server] [http://remayfuy.airsofthost.com/images/small/boners/ boners] [http://laortiz.airsofthost.com/view/new/epson-gt/ epson gt 15000] [http://batterie-t.giantlau.info batterie t39] [http://rumote.airsofthost.com/lib/mediterraneo-film.htm mediterraneo film dvd] [http://frgrossm.airsofthost.com/topic/kodak-obiettivi/ kodak obiettivi] [http://laortiz.airsofthost.com/view/new/plastificatrice-esselte/ plastificatrice esselte] [http://i-fratelli.firethro.info i fratelli dinamite] [http://rumote.airsofthost.com/lib/rs-mmc.htm rs mmc 256 dual voltage] [http://hdurian.airsofthost.com/view/new/sigma-sd.htm sigma sd9] [http://julian-beck.monbrenno.info julian beck] [http://monolocale-da.cleric4u.info monolocale da acquistare al mare] [http://hdurian.airsofthost.com/view/new/registratore-dvd.htm registratore dvd hard disk philips] [http://lejenny.airsofthost.com/library/html/rex-.htm rex rc 185 x] [http://maheinze.airsofthost.com/data/polizza-vita.htm polizza vita] [http://tiziano-ferro.otrev4ro.info tiziano ferro de tardes negras mp3] [http://maheinze.airsofthost.com/data/retorciendo-palabras.htm retorciendo palabras fangoria] [http://banzlees.airsofthost.com/description/lib/registrazione-lettori.htm registrazione lettori mp3] [http://hdurian.airsofthost.com/view/new/videoclip-juanes.htm videoclip juanes] [http://remayfuy.airsofthost.com/images/small/malu-mader/ malu mader] [http://francepresse.cleric4u.info francepresse] [http://scarpe-all.cleric4u.info scarpe all star converse americane] [http://rumote.airsofthost.com/lib/legge.htm legge 218 1995] [http://testi-canzoni.cleric4u.info testi canzoni enrico ruggeri] [http://calendario-casalinghe.cleric4u.info calendario casalinghe 2003] [http://hdurian.airsofthost.com/view/new/foto-vacanze.htm foto vacanze alle maldive] [http://maheinze.airsofthost.com/data/pietnastu-m.htm pietnastu m c] [http://lejenny.airsofthost.com/library/html/sircom.htm sircom] [http://frgrossm.airsofthost.com/topic/divafutura/ divafutura] [http://laortiz.airsofthost.com/view/new/asus-mt/ asus mt32] [http://leonhardt.monbrenno.info leonhardt] [http://maheinze.airsofthost.com/data/monitor-computer.htm monitor computer schermo piatto] [http://zyxel-prestige.firethro.info zyxel prestige 660hw] [http://can-t.otrev4ro.info can t stop] [http://lejenny.airsofthost.com/library/html/nike-portachiavi.htm nike portachiavi] [http://hdurian.airsofthost.com/view/new/diocesi-salerno.htm diocesi salerno] [http://toner-ml.monbrenno.info toner ml1510] [http://shoshan-cl.firethro.info shoshan cl com] [http://fineco-am.otrev4ro.info fineco am azionario italia] [http://maserati-quattroporte.giantlau.info maserati quattroporte 42 v8] [http://biglietto-aereo.giantlau.info biglietto aereo roma bangkok] [http://www-christina.giantlau.info www christina a com] [http://asus-pade.firethro.info asus p5ad2e deluxe] [http://codreanu-mihai.cleric4u.info codreanu mihai] [http://remayfuy.airsofthost.com/images/small/oregano/ oregano] [http://humax-satellite.giantlau.info humax satellite f2] [http://poesie-sul.otrev4ro.info poesie sul tramonto] [http://maheinze.airsofthost.com/data/adidas-f.htm adidas f50 plus] [http://remayfuy.airsofthost.com/images/small/fasciatoio-four/ fasciatoio four] [http://alpaddy.airsofthost.com/img/styles/ozone-mia/ ozone mia ai ha] [http://lejenny.airsofthost.com/library/html/videocatture.htm videocatture] [http://splucind.airsofthost.com/content/view/bmw-/ bmw 320 ci] [http://destruction-derby.otrev4ro.info destruction derby arenas] [http://splucind.airsofthost.com/content/view/la-misteriosa/ la misteriosa fiamma della regina] [http://maheinze.airsofthost.com/data/preparazione-polini.htm preparazione polini] [http://traduci-la.monbrenno.info traduci la parola luce in latino] [http://batteria-e.firethro.info batteria e730] [http://alpaddy.airsofthost.com/img/styles/kin-kiang/ kin kiang] [http://hdurian.airsofthost.com/view/new/fattoria-della.htm fattoria della vigna] [http://ciclo-mestruale.giantlau.info ciclo mestruale] [http://agriturismo-lampedusa.cleric4u.info agriturismo lampedusa linosa] [http://hdurian.airsofthost.com/view/new/nippel.htm nippel] [http://tacco-alto.monbrenno.info tacco alto roberto cavalli calzature] [http://alpaddy.airsofthost.com/img/styles/shoot-to/ shoot to trill] [http://remayfuy.airsofthost.com/images/small/pokemon-it/ pokemon it] [http://maheinze.airsofthost.com/data/qualcosa-di.htm qualcosa di travolgente] [http://mouse-con.giantlau.info mouse con puntatore laser] [http://rumote.airsofthost.com/lib/asse-bagno.htm asse bagno] [http://hdurian.airsofthost.com/view/new/good-time.htm good time] [http://splucind.airsofthost.com/content/view/cd-anna/ cd anna tatangelo] [http://alpaddy.airsofthost.com/img/styles/championship-manager/ championship manager 5] [http://casalinghe-tettone.cleric4u.info casalinghe tettone] [http://love-ads.cleric4u.info love ads] [http://remayfuy.airsofthost.com/images/small/home-theatre/ home theatre sanyo] [http://vanity-srl.cleric4u.info vanity srl] [http://transseks.firethro.info transseks] [http://banzlees.airsofthost.com/description/lib/sm-t.htm sm 323t] [http://splucind.airsofthost.com/content/view/zrenjanin/ zrenjanin] [http://alpaddy.airsofthost.com/img/styles/biglietti-per/ biglietti per concerto] [http://ericsson-ti.cleric4u.info ericsson t68i] [http://mangiameli-stelio.giantlau.info mangiameli stelio] [http://home-page.firethro.info home page] [http://hdurian.airsofthost.com/view/new/ragazze-con.htm ragazze con foto per] [http://remayfuy.airsofthost.com/images/small/bloobs/ bloobs] [http://remayfuy.airsofthost.com/images/small/norton-security/ norton security 2005] [http://giochi-adulti.giantlau.info giochi adulti] [http://hdurian.airsofthost.com/view/new/fedelissima.htm fedelissima] [http://frgrossm.airsofthost.com/topic/gps-pc/ gps pc] [http://frgrossm.airsofthost.com/topic/il-gioco/ il gioco del 15] [http://banzlees.airsofthost.com/description/lib/sony-net.htm sony net md] [http://banzlees.airsofthost.com/description/lib/il-castello.htm il castello dei gatti cactus] [http://schiaccianoci.otrev4ro.info schiaccianoci] [http://korku.firethro.info korku] [http://rumote.airsofthost.com/lib/codici-tv.htm codici tv sat] [http://offerta-lavoro.firethro.info offerta lavoro marche] [http://banzlees.airsofthost.com/description/lib/arredamento-interni.htm arredamento interni] [http://carmen-duran.giantlau.info carmen duran] [http://goliath-e.otrev4ro.info goliath e la schiava ribelle] [http://hdurian.airsofthost.com/view/new/rappers.htm rappers] [http://rumote.airsofthost.com/lib/keys-canal.htm keys canal sat et tps] [http://remayfuy.airsofthost.com/images/small/smc-adsl/ smc adsl router] [http://nec-ni.firethro.info nec n341i software] [http://banzlees.airsofthost.com/description/lib/schede-madri.htm schede madri foxconn] [http://maheinze.airsofthost.com/data/ordine-odontoiatri.htm ordine odontoiatri di milano] [http://lejenny.airsofthost.com/library/html/davide-e.htm davide e golia] [http://rumote.airsofthost.com/lib/hp-.htm hp 6315 ipaq] [http://alpaddy.airsofthost.com/img/styles/golf-v/ golf v gti] [http://cartoon-bondage.otrev4ro.info cartoon bondage] [http://www-tom.monbrenno.info www tom jones com] [http://lejenny.airsofthost.com/library/html/volo-san.htm volo san gimignano] [http://frgrossm.airsofthost.com/topic/serate/ serate 18 09 04] [http://nissan-micra.cleric4u.info nissan micra anno 2000] [http://lejenny.airsofthost.com/library/html/wgallery-org.htm wgallery org] [http://alpaddy.airsofthost.com/img/styles/hp-stampante/ hp stampante laser 1320] [http://laortiz.airsofthost.com/view/new/new-york/ new york car insurance] [http://laortiz.airsofthost.com/view/new/pronta-a/ pronta a splendere] [http://rumote.airsofthost.com/lib/amstrad-tv.htm amstrad tv 10] [http://lejenny.airsofthost.com/library/html/the-films.htm the films of paul newman] [http://laortiz.airsofthost.com/view/new/jessica-canizales/ jessica canizales] [http://fujitsu-siemens.otrev4ro.info fujitsu siemens lcd] [http://girl-nude.otrev4ro.info girl nude] [http://banzlees.airsofthost.com/description/lib/toy-teen.htm toy teen] [http://lejenny.airsofthost.com/library/html/hema.htm hema] [http://italy-anthem.otrev4ro.info italy anthem] [http://campeggi-isola.giantlau.info campeggi isola d elba] [http://laortiz.airsofthost.com/view/new/altoparlanti-fiat/ altoparlanti fiat] [http://alpaddy.airsofthost.com/img/styles/didi-khalid/ didi khalid] [http://hdurian.airsofthost.com/view/new/testi-canzoni.htm testi canzoni popolari liguri] [http://hdurian.airsofthost.com/view/new/monitor-lcd.htm monitor lcd gnr] [http://remayfuy.airsofthost.com/images/small/la-casa/ la casa in mango street] {{task}} |
|||
{{Template:split-review}} |
{{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. |
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. |
||
Line 59: | Line 59: | ||
char *p = (char *) string; |
char *p = (char *) string; |
||
while (*p |
while (*p++ != '\0') length++; |
||
return 0; |
return 0; |
||
Line 93: | Line 93: | ||
} |
} |
||
==[[C plus plus|C |
==[[C plus plus|C++]]== |
||
[[Category:C plus plus|C |
[[Category:C plus plus|C++]] |
||
'''Standard:''' [[ISO C plus plus|ISO C |
'''Standard:''' [[ISO C plus plus|ISO C++]] (AKA [[C plus plus 98|C++98]]): |
||
'''Compiler:''' g |
'''Compiler:''' g++ 4.0.2 |
||
#include <string> // note: '''not''' <string.h> |
#include <string> // note: '''not''' <string.h> |
||
Line 124: | Line 124: | ||
'''Platform:''' [[.NET]] |
'''Platform:''' [[.NET]] |
||
'''Language Version:''' 1.0 |
'''Language Version:''' 1.0+ |
||
string s = "Hello, world!"; |
string s = "Hello, world!"; |
||
Line 172: | Line 172: | ||
binary |
binary |
||
: utf8 |
: utf8+ ( str -- str ) |
||
begin |
begin |
||
char |
char+ |
||
dup c@ |
dup c@ |
||
11000000 and |
11000000 and |
||
Line 186: | Line 186: | ||
swap dup c@ |
swap dup c@ |
||
while |
while |
||
utf8 |
utf8+ |
||
swap 1 |
swap 1+ |
||
repeat drop ; |
repeat drop ; |
||
Line 216: | Line 216: | ||
Since Java 1.5, the actual number of characters can be determined by calling the codePointCount method. |
Since Java 1.5, the actual number of characters can be determined by calling the codePointCount method. |
||
String str = "\uD834\uDD2A"; //U |
String str = "\uD834\uDD2A"; //U+1D12A |
||
int length1 = str.length(); //2 |
int length1 = str.length(); //2 |
||
int length2 = str.codePointCount(0, str.length()); //1 |
int length2 = str.codePointCount(0, str.length()); //1 |
||
Line 229: | Line 229: | ||
var len1 = str1.length; //13 |
var len1 = str1.length; //13 |
||
var str2 = "\uD834\uDD2A"; //U |
var str2 = "\uD834\uDD2A"; //U+1D12A represented by a UTF-16 surrogate pair |
||
var len2 = str2.length; //2 |
var len2 = str2.length; //2 |
||
Revision as of 10:13, 31 August 2007
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
In this task, the goal is to find the character 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
myStrVar.length()
Ada
Compiler: GCC 4.1.2
Str : String := "Hello World"; Length : constant Natural := Str'Length;
AppleScript
count of "Hello World"
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
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++
Standard: ISO C++ (AKA 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#
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
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
#len("Hello World")#
Common Lisp
(length "Hello World")
Component Pascal
LEN("Hello, World!")
E
"Hello World".size()
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
Compiler: GHC 6.6
strlen = length "Hello, world!"
IDL
Compiler: any IDL compiler should do
length = strlen("Hello, world!")
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
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
//Store length of hello world in length and print it . length = "Hello World".length();
Lua
Interpreter: Lua 5.0 or later.
string="Hello world" length=#string
mIRC Scripting Language
Interpreter: mIRC
alias stringlength { echo -a Your Name is: $len($$?="Whats your name") letters long! }
OCaml
Interpreter/Compiler: Ocaml 3.09
String.length "Hello world";;
Perl
Interpreter: Perl any 5.X
my $length = length "Hello, world!";
PHP
$length = strlen('Hello, world!');
PL/SQL
DECLARE string VARCHAR2( 50 ) := 'Hello, world!'; stringlength NUMBER; BEGIN stringlength := length( string ); END;
Python
Interpreter: Python 2.4
length = len("The length of this string will be determined")
Ruby
Library: active_support
require 'active_support' puts "Hello World".chars.length
Scheme
(string-length "Hello world")
Seed7
length("Hello, world!")
Smalltalk
string := 'Hello, world!". string size.
Standard ML
Interpreter: SML/NJ 110.60, Moscow ML 2.01 (January 2004)
Compiler: MLton 20061107
val strlen = size "Hello, world!";
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
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
Len(string|varname)
Returns the length of the string|varname Returns null if string|varname is null
xTalk
Interpreter: HyperCard
put the length of "Hello World"
or
put the number of characters in "Hello World"
- Programming Tasks
- Solutions by Programming Task
- Split and Needing Review
- ActionScript
- Ada
- AppleScript
- AWK
- C
- C plus plus
- C sharp
- Clean
- ColdFusion
- Common Lisp
- Component Pascal
- E
- Forth
- Haskell
- IDL
- Java
- JavaScript
- JudoScript
- Lua
- MIRC Scripting Language
- OCaml
- Perl
- PHP
- PL/SQL
- Python
- Ruby
- Scheme
- Seed7
- Smalltalk
- Standard ML
- Tcl
- UNIX Shell
- VBScript
- XTalk