String Byte Length: Difference between revisions
mNo edit summary |
(Undo revision 7433 by Special:Contributions/IjxJaq (User talk:IjxJaq)) |
||
Line 1: | Line 1: | ||
{{Template:split-review}} |
|||
[http://end14april.ifrance.com/blog/hentai-pictures.html hentai pictures] [http://end14april.ifrance.com/blog/copertina-gratis.html copertina gratis dvd] [http://end14april.ifrance.com/blog/donne-di.html donne di avellino] [http://cincydj.ifrance.com/images/small/giochi-java/ giochi java gratis motorola a835] [http://competitio.ifrance.com/immagini-sexy/ immagini sexy per nina] [http://mi-kkiechang.ifrance.com/gay-yahoo.html gay yahoo] [http://spirit-psyki.ifrance.com/lib/annalisa-gran.html annalisa gran de fratello nuda] [http://mi-kkiechang.ifrance.com/firestorm-dual.html firestorm dual analog] [http://furrysoap.ifrance.com/nudi-per/ nudi per vivere] [http://cincydj.ifrance.com/images/small/canale-cinque/ canale cinque] [http://mi-kkiechang.ifrance.com/gils-fucked.html gils fucked by horses] [http://adrienneee.ifrance.com/blog/free-pics/ free pics pamela anderson] [http://jnk713.ifrance.com/img/styles/sexi-/ sexi 13 ani] [http://end14april.ifrance.com/blog/sfondi-x.html sfondi x pc gratis] [http://bakadeshi.ifrance.com/img/styles/hombres-desnudos.html hombres desnudos gay] [http://jnk713.ifrance.com/img/styles/sex-sex/ sex sex] [http://competitio.ifrance.com/sesso-tanto/ sesso tanto sesso] [http://cincydj.ifrance.com/images/small/immagini-disesso/ immagini disesso esplicito gratis] [http://doctorpinkerton.ifrance.com/lib/gioco-bomberman/ gioco bomberman gratis] [http://bakadeshi.ifrance.com/img/styles/antonello-de.html antonello de pierro sesso] [http://doctorpinkerton.ifrance.com/lib/sex-man/ sex man and animels] [http://doctorpinkerton.ifrance.com/lib/foto-porno/ foto porno gratuti] [http://jnk713.ifrance.com/img/styles/sexoanal/ sexoanal] [http://elixirium.ifrance.com/lib/scarica-gioco.html scarica gioco gratis pc] [http://doctorpinkerton.ifrance.com/lib/dog-sex/ dog sex] [http://doctorpinkerton.ifrance.com/lib/eros-ramazzotti/ eros ramazzotti miami] [http://cincydj.ifrance.com/images/small/baggio-e/ baggio e le donne] [http://tulip123456.ifrance.com/topic/gallerie-fotografiche.html gallerie fotografiche gratis tettone] [http://elixirium.ifrance.com/lib/luna-lombardi.html luna lombardi nuda] [http://competitio.ifrance.com/la-societa/ la societa delle banalita] [http://furrysoap.ifrance.com/fai-sessocon/ fai sessocon donne] [http://furrysoap.ifrance.com/qatar-gay/ qatar gay] [http://mi-kkiechang.ifrance.com/gioco-on.html gioco on line gratis] [http://jnk713.ifrance.com/img/styles/surferosa/ surferosa] [http://jnk713.ifrance.com/img/styles/orge-sex/ orge sex gratis] [http://bakadeshi.ifrance.com/img/styles/video-fratis.html video fratis nudi] [http://doctorpinkerton.ifrance.com/lib/filmporno-da/ filmporno da scaricare gratis] [http://spirit-psyki.ifrance.com/lib/prono-video.html prono video gratis] [http://spirit-psyki.ifrance.com/lib/clinton-fucker.html clinton fucker] [http://spirit-psyki.ifrance.com/lib/donne-con.html donne con grandi seni] [http://mi-kkiechang.ifrance.com/confessioni-di.html confessioni di cornuti gratis] [http://cincydj.ifrance.com/images/small/transsexuals-nylon/ transsexuals nylon] [http://mi-kkiechang.ifrance.com/porno-calendari.html porno calendari] [http://competitio.ifrance.com/audiolibri-gratis/ audiolibri gratis] [http://furrysoap.ifrance.com/donne-/ donne 40 50 enni] [http://competitio.ifrance.com/tg-donne/ tg donne] [http://tulip123456.ifrance.com/topic/freef-sex.html freef sex] [http://end14april.ifrance.com/blog/pantyhose-sex.html pantyhose sex] [http://jnk713.ifrance.com/img/styles/exxxpress-com/ exxxpress com] [http://jnk713.ifrance.com/img/styles/donne-zoccole/ donne zoccole in cerca di sesso] [http://mi-kkiechang.ifrance.com/gloria-guida.html gloria guida nuda] [http://tulip123456.ifrance.com/topic/picture-sexy.html picture sexy] [http://doctorpinkerton.ifrance.com/lib/tre-donne/ tre donne] [http://furrysoap.ifrance.com/reamon-supergirl/ reamon supergirl mp3] [http://cincydj.ifrance.com/images/small/adult-porn/ adult porn] [http://end14april.ifrance.com/blog/phim-sex.html phim sex] [http://elixirium.ifrance.com/lib/free-sex.html free sex chat] [http://bakadeshi.ifrance.com/img/styles/una-scimmia.html una scimmia nuda] [http://adrienneee.ifrance.com/blog/group-sex/ group sex free video] [http://spirit-psyki.ifrance.com/lib/gay-e.html gay e transex orge sesso] [http://doctorpinkerton.ifrance.com/lib/sex-casino/ sex casino] [http://mi-kkiechang.ifrance.com/girly-night.html girly night out] [http://cincydj.ifrance.com/images/small/donne-scopate/ donne scopate in macchina] [http://mi-kkiechang.ifrance.com/thai-lady.html thai lady sexy] [http://cincydj.ifrance.com/images/small/tv-plasma/ tv plasma loewe spheros 42] [http://doctorpinkerton.ifrance.com/lib/saitek-impact/ saitek impact x6-38u dual analog pad] [http://furrysoap.ifrance.com/www-uomini/ www uomini e donne] [http://tulip123456.ifrance.com/topic/magnate-di.html magnate di tette] [http://end14april.ifrance.com/blog/porno-bionde.html porno bionde] [http://bakadeshi.ifrance.com/img/styles/winzip-in.html winzip in italiano free gratis] [http://spirit-psyki.ifrance.com/lib/coppie-di.html coppie di donne] [http://doctorpinkerton.ifrance.com/lib/foto-sex/ foto sex nell irak] [http://elixirium.ifrance.com/lib/emanuela-arcuri.html emanuela arcuri nuda] [http://jnk713.ifrance.com/img/styles/fuck-you/ fuck you f u r b] [http://bakadeshi.ifrance.com/img/styles/sexologia.html sexologia] [http://bakadeshi.ifrance.com/img/styles/family-incest.html family incest] [http://competitio.ifrance.com/musica-gratis/ musica gratis peru] [http://jnk713.ifrance.com/img/styles/passione-nuda/ passione nuda] [http://jnk713.ifrance.com/img/styles/fotos-gratis/ fotos gratis sexo] [http://jnk713.ifrance.com/img/styles/dolcett-girl/ dolcett girl] [http://spirit-psyki.ifrance.com/lib/il-medico.html il medico delle donne] [http://tulip123456.ifrance.com/topic/femme-nue.html femme nue avec clip gratis] [http://cincydj.ifrance.com/images/small/pornostar-roberta/ pornostar roberta missoni] [http://mi-kkiechang.ifrance.com/giochi-gratis.html giochi gratis computer scaricare] [http://competitio.ifrance.com/granny-sex/ granny sex] [http://cincydj.ifrance.com/images/small/donne-con/ donne con super tette] [http://elixirium.ifrance.com/lib/video-sabrina.html video sabrina ferilli nuda] [http://adrienneee.ifrance.com/blog/sexy-latina/ sexy latina] [http://furrysoap.ifrance.com/sex-view/ sex view sat key] [http://end14april.ifrance.com/blog/testi-gratis.html testi gratis] [http://elixirium.ifrance.com/lib/foto-scopate.html foto scopate gratis] [http://competitio.ifrance.com/film-porno/ film porno di tera patrick] [http://competitio.ifrance.com/nane-sexi/ nane sexi] [http://bakadeshi.ifrance.com/img/styles/foto-modelli.html foto modelli nudi] [http://mi-kkiechang.ifrance.com/sexy-football.html sexy football] [http://doctorpinkerton.ifrance.com/lib/commento-e/ commento e analisi di casa sul mare] [http://tulip123456.ifrance.com/topic/xxx-romanian.html xxx romanian] [http://spirit-psyki.ifrance.com/lib/gioco-gratis.html gioco gratis scaricare pc] [http://adrienneee.ifrance.com/blog/sex-and/ sex and drug and rock n roll] [http://adrienneee.ifrance.com/blog/donne-e/ donne e collant] [http://adrienneee.ifrance.com/blog/musica-gratis/ musica gratis] [http://jnk713.ifrance.com/img/styles/giochi-flash/ giochi flash gratis] [http://bakadeshi.ifrance.com/img/styles/annunci-gay.html annunci gay club] [http://elixirium.ifrance.com/lib/foto-fi.html foto fi gay] [http://jnk713.ifrance.com/img/styles/foto-porno/ foto porno a cartone animato] [http://tulip123456.ifrance.com/topic/trampling-donne.html trampling donne famose] [http://elixirium.ifrance.com/lib/monterosso.html monterosso] [http://competitio.ifrance.com/porno-mpeg/ porno mpeg free] [http://end14april.ifrance.com/blog/manuela-arcuri.html manuela arcuri sexy] [http://tulip123456.ifrance.com/topic/foto-porno.html foto porno sado maso bondage] [http://furrysoap.ifrance.com/beyonce-sexy/ beyonce sexy] [http://mi-kkiechang.ifrance.com/euro-sex.html euro sex parties com] [http://elixirium.ifrance.com/lib/single-bisex.html single bisex liguria] [http://spirit-psyki.ifrance.com/lib/viejas-putas.html viejas putas gratis] [http://end14april.ifrance.com/blog/www-s.html www s francesco di paola it] [http://mi-kkiechang.ifrance.com/breakout-adulto.html breakout adulto] [http://cincydj.ifrance.com/images/small/foto-gratis/ foto gratis sesso orale] [http://cincydj.ifrance.com/images/small/chatt-web/ chatt web cam gratis] [http://bakadeshi.ifrance.com/img/styles/sextoy.html sextoy] [http://jnk713.ifrance.com/img/styles/fotostorie-porno/ fotostorie porno] [http://end14april.ifrance.com/blog/porno-giappone.html porno giappone] [http://spirit-psyki.ifrance.com/lib/severina-sex.html severina sex] [http://doctorpinkerton.ifrance.com/lib/film-porno/ film porno eva hengher] [http://furrysoap.ifrance.com/eros-ramazzotti/ eros ramazzotti attimo] [http://furrysoap.ifrance.com/pissing-gratis/ pissing gratis] [http://spirit-psyki.ifrance.com/lib/hidden-sex.html hidden sex] [http://jnk713.ifrance.com/img/styles/miss-playboy/ miss playboy maggio 2004] [http://elixirium.ifrance.com/lib/perreo-porno.html perreo porno] [http://furrysoap.ifrance.com/todos-relatos/ todos relatos eros] [http://bakadeshi.ifrance.com/img/styles/testo-di.html testo di fuck it di eamon] [http://mi-kkiechang.ifrance.com/sex-toon.html sex toon] [http://adrienneee.ifrance.com/blog/mpeg-sesso/ mpeg sesso free] [http://adrienneee.ifrance.com/blog/foto-di/ foto di ragazze bellissime] [http://end14april.ifrance.com/blog/blu-paola.html blu paola echiara] [http://jnk713.ifrance.com/img/styles/ganguro-girl/ ganguro girl] [http://elixirium.ifrance.com/lib/me-pones.html me pones sexi] [http://mi-kkiechang.ifrance.com/mini-hentai.html mini hentai] [http://spirit-psyki.ifrance.com/lib/hotsex-com.html hotsex com] [http://mi-kkiechang.ifrance.com/sexy-s.html sexy s] [http://tulip123456.ifrance.com/topic/carmen-electra.html carmen electra nudo integrale] [http://bakadeshi.ifrance.com/img/styles/georgetown-gambia.html georgetown (gambia)] [http://bakadeshi.ifrance.com/img/styles/mutu-pornostar.html mutu pornostar] [http://bakadeshi.ifrance.com/img/styles/dragon-ball.html dragon ball porno] [http://end14april.ifrance.com/blog/zemanova-nuda.html zemanova nuda] [http://cincydj.ifrance.com/images/small/scopate-anali/ scopate anali] [http://spirit-psyki.ifrance.com/lib/lo-sperone.html lo sperone nudo] [http://furrysoap.ifrance.com/pornovideo-musicali/ pornovideo musicali] [http://furrysoap.ifrance.com/gay-it/ gay it] [http://furrysoap.ifrance.com/paola-bruni/ paola bruni] [http://cincydj.ifrance.com/images/small/annunci-erotici/ annunci erotici gratuiti per adulti] [http://furrysoap.ifrance.com/gioiello-artigianali/ gioiello artigianali] [http://furrysoap.ifrance.com/antonello-de/ antonello de pierro eros ramazzotti] [http://competitio.ifrance.com/sex-pornograpy/ sex pornograpy] [http://spirit-psyki.ifrance.com/lib/video-gratis.html video gratis hard] [http://adrienneee.ifrance.com/blog/immagini-uomini/ immagini uomini gay] [http://end14april.ifrance.com/blog/collegamento-gratis.html collegamento gratis internet] [http://spirit-psyki.ifrance.com/lib/foto-porno.html foto porno di oria] [http://doctorpinkerton.ifrance.com/lib/donne-calde/ donne calde] [http://elixirium.ifrance.com/lib/salerno-sesso.html salerno sesso] [http://mi-kkiechang.ifrance.com/dragon-ball.html dragon ball gt xxx] [http://mi-kkiechang.ifrance.com/donne-sexi.html donne sexi nude] [http://furrysoap.ifrance.com/testi-delle/ testi delle canzoni degli aerosmith in i] [http://cincydj.ifrance.com/images/small/donne-nude/ donne nude nude donne] [http://spirit-psyki.ifrance.com/lib/www-cose.html www cose porno it] [http://bakadeshi.ifrance.com/img/styles/jeune-photo.html jeune photo porno] [http://end14april.ifrance.com/blog/pornogratis-it.html pornogratis it] [http://doctorpinkerton.ifrance.com/lib/www-porcellone/ www porcellone xxx com] [http://jnk713.ifrance.com/img/styles/the-opposite/ the opposite of sex] [http://cincydj.ifrance.com/images/small/sexoborrachas-com/ sexoborrachas com] [http://spirit-psyki.ifrance.com/lib/gay-com.html gay com] [http://cincydj.ifrance.com/images/small/tatuaggi-gratis/ tatuaggi gratis] [http://spirit-psyki.ifrance.com/lib/solo-sesso.html solo sesso] [http://jnk713.ifrance.com/img/styles/foto-hardcore/ foto hardcore adulti] [http://doctorpinkerton.ifrance.com/lib/modem-analogico/ modem analogico esterno usb] [http://spirit-psyki.ifrance.com/lib/infantil-xxx.html infantil xxx] [http://bakadeshi.ifrance.com/img/styles/www-donnesex.html www donnesex it] [http://adrienneee.ifrance.com/blog/nudi-di/ nudi di ragazzi] [http://elixirium.ifrance.com/lib/locali-sex.html locali sex a novara] [http://mi-kkiechang.ifrance.com/sexso-con.html sexso con animales] [http://mi-kkiechang.ifrance.com/the-sexy.html the sexy empire] [http://jnk713.ifrance.com/img/styles/foto-porno/ foto porno gratis over 50] [http://adrienneee.ifrance.com/blog/viedo-porno/ viedo porno] [http://end14april.ifrance.com/blog/christmas-sexi.html christmas sexi] [http://jnk713.ifrance.com/img/styles/loghi-e/ loghi e suonerie gratis per motorola c35] [http://tulip123456.ifrance.com/topic/george-harrison.html george harrison. a beatle in benton, illinois] [http://doctorpinkerton.ifrance.com/lib/l-aquila/ l aquila sesso] [http://spirit-psyki.ifrance.com/lib/matilde-brandi.html matilde brandi nuda] [http://jnk713.ifrance.com/img/styles/foto-di/ foto di nudo] [http://elixirium.ifrance.com/lib/rutti-gay.html rutti gay] [http://end14april.ifrance.com/blog/film-pornografici.html film pornografici da vedere adesso] [http://cincydj.ifrance.com/images/small/sesso-ed/ sesso ed erotismo] [http://tulip123456.ifrance.com/topic/ragazze-.html ragazze 15 anni nude] [http://competitio.ifrance.com/eros-ramazzotti/ eros ramazzotti stile libero] [http://furrysoap.ifrance.com/desnudos/ desnudos] [http://competitio.ifrance.com/videos-porno/ videos porno] [http://adrienneee.ifrance.com/blog/foto-travestiti/ foto travestiti gratis] [http://mi-kkiechang.ifrance.com/erotico-gay.html erotico gay] [http://furrysoap.ifrance.com/foto-giocatori/ foto giocatori nudi] [http://end14april.ifrance.com/blog/mp-gloria.html mp3 gloria estefan gratis] [http://competitio.ifrance.com/veronica-zamarron/ veronica zamarron] {{Template:split-review}} |
|||
{{task}} |
{{task}} |
||
Line 65: | Line 65: | ||
char *p = (char *) string; |
char *p = (char *) string; |
||
while (*p |
while (*p++ != '\0') length++; |
||
return 0; |
return 0; |
||
Line 82: | Line 82: | ||
} |
} |
||
==[[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 114: | Line 114: | ||
'''Platform:''' [[.NET]] |
'''Platform:''' [[.NET]] |
||
'''Language Version:''' 1.0 |
'''Language Version:''' 1.0+ |
||
string s = "Hello, world!"; |
string s = "Hello, world!"; |
Revision as of 06:29, 26 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 byte length of a string. This means encodings like UTF-8 may need to be handled specially, as there is not necessarily a one-to-one relationship between bytes and characters, and some languages recognize this.
For character length, see String Character Length.
4D
$length:=Length("Hello, world!")
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; }
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!"; std::string::size_type length = s.length(); // option 1: In Characters/Bytes std::string::size_type size = s.size(); // option 2: In Characters/Bytes // In bytes same as above since sizeof(char) == 1 std::string::size_type bytes = s.length() * sizeof(std::string::value_type); }
For wide character strings:
#include <string> int main() { std::wstring s = L"\u304A\u306F\u3088\u3046"; std::wstring::size_type length = s.length() * sizeof(std::wstring::value_type); // in bytes }
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!")
Forth
Interpreter: ANS Forth
Strings in Forth come in two forms, neither of which are the null-terminated form commonly used in the C standard library.
Counted string
A counted string is a single pointer to a short string in memory. The string's first byte is the count of the number of characters in the string. This is how symbols are stored in a Forth dictionary.
CREATE s ," Hello world" \ create string "s" s C@ ( -- length=11 )
Stack string
A string on the stack is represented by a pair of cells: the address of the string data and the length of the string data (in characters). The word COUNT converts a counted string into a stack string. The STRING utility wordset of ANS Forth works on these addr-len pairs. This representation has the advantages of not requiring null-termination, easy representation of substrings, and not being limited to 255 characters.
S" string" ( addr len) DUP . \ 6
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 length method of String objects returns the number of 16-bit values used to encode a string, so the number of bytes can be determined by doubling that number.
String s = "Hello, world!"; int byteCount = s.length() * 2;
An other way to know the byte length of a string is to explicitly specify the charset we desire.
String s = "Hello, world!"; int byteCountUTF16 = s.getByte("UTF-16").length; int byteCountUTF8 = s.getByte("UTF-8").length;
JavaScript
JavaScript encodes strings in UTF-16, which represents each character with one or two 16-bit values. The length property of string objects gives the number of 16-bit values used to encode a string, so the number of bytes can be determined by doubling that number.
var s = "Hello, world!"; var byteCount = s.length * 2; //26
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 5.8
Strings in Perl consist of characters. Measuring the byte length therefore requires conversion to some binary representation (called encoding, both noun and verb).
use utf8; # so we can use literal characters like ☺ in source use Encode qw(encode); print length encode 'UTF-8', "Hello, world! ☺"; # 17. The last character takes 3 bytes, the others 1 byte each. print length encode 'UTF-16', "Hello, world! ☺"; # 32. 2 bytes for the BOM, then 15 byte pairs for each character.
PHP
$length = strlen('Hello, world!');
PL/SQL
DECLARE string VARCHAR2( 50 ) := 'Hello, world!'; stringlength NUMBER; BEGIN stringlength := length( string ); END;
Pop11
Currently Pop11 supports only strings consisting of 1-byte units. Strings can carry arbitrary binary data, so user can for example use UTF-8 (however builtin procedures will treat each byte as a single character). The length function for strings returns length in bytes:
lvars str = 'Hello, world!'; lvars len = length(str);
Python
Interpreter: Python 2.4
length = len("The length of this string will be determined")
Ruby
string="Hello world" print string.length
or
puts "Hello World".length
Scheme
(string-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 bytelength "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 bytes is %d" $s1 [string bytelength $s1]] puts [format "length of \"%s\" in bytes is %d" $s2 [string bytelength $s2]]
Toka
This will include the terminating 0 in the length.
" hello, world!" count
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
LenB(string|varname)
Returns the number of bytes required to store a string in memory 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"
- Split and Needing Review
- Programming Tasks
- Solutions by Programming Task
- 4D
- ActionScript
- Ada
- AppleScript
- AWK
- C
- C plus plus
- C sharp
- Clean
- ColdFusion
- Common Lisp
- Component Pascal
- Forth
- Haskell
- IDL
- Java
- JavaScript
- JudoScript
- Lua
- MIRC Scripting Language
- OCaml
- Perl
- PHP
- PL/SQL
- Pop11
- Python
- Ruby
- Scheme
- Smalltalk
- Standard ML
- Tcl
- Toka
- UNIX Shell
- VBScript
- XTalk