String Byte Length: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
(revert spam)
Line 1: Line 1:
{{Template:split-review}}
[http://akmokanzen.ifrance.com/images/small/ohio-cose.htm ohio cose fare] [http://toofarfrommaybe.ifrance.com/view/new/dvdr-dvd/ dvd-r dvd r recorder vhs hdd] [http://girlwho-is.ifrance.com/img/styles/torino-lamezia.htm torino lamezia] [http://demurediablo.ifrance.com/library/html/testo-canzone/ testo canzone cantante d] [http://akmokanzen.ifrance.com/images/small/dravite.htm dravite] [http://lordsander.ifrance.com/topic/nuova-volkswagen.htm nuova volkswagen tdi 140 cv diesel auto] [http://deviantrus.ifrance.com/topic/il-pescatore/ il pescatore tab] [http://voltia.ifrance.com/content/view/clonare.htm clonare] [http://voltia.ifrance.com/content/view/mercedes-e.htm mercedes e 230 s.w. avantgarde] [http://demurediablo.ifrance.com/library/html/great-expectations/ great expectations] [http://jdawsona.ifrance.com/data/hey-sexy/ hey sexy lady shaggy lyrics] [http://tizolaa.ifrance.com/web/solo-di/ solo di eamon gratis] [http://yeeden.ifrance.com/img/styles/biciclette-carnielli/ biciclette carnielli 2000] [http://singaporepets.ifrance.com/library/html/sesso-annunci.htm sesso annunci gratis] [http://girlwho-is.ifrance.com/img/styles/commedia.htm commedia] [http://igaros.ifrance.com/lib/jovi-have/ jovi have] [http://voltia.ifrance.com/content/view/dynax-.htm dynax 40 konica minolta] [http://deviantrus.ifrance.com/topic/cognatina/ cognatina] [http://tat-ooin.ifrance.com/resources/articles/serenata-celeste.htm serenata celeste] [http://tizolaa.ifrance.com/web/www-musica/ www musica hardcore it] [http://speedofsoun.ifrance.com/text/directory/freienfeld.htm freienfeld] [http://oiyaoi.ifrance.com/images/small/uno-scomodo/ uno scomodo testimone] [http://tizolaa.ifrance.com/web/il-terrore/ il terrore dei gangster] [http://speedofsoun.ifrance.com/text/directory/ostelli.htm ostelli] [http://kalian42.ifrance.com/text/directory/www-google/ www google it smack down] [http://yeeden.ifrance.com/img/styles/a-d/ a d a] [http://noxuhax.ifrance.com/content/view/libri-bob.htm libri bob marley] [http://speedofsoun.ifrance.com/text/directory/formaggini-susanna.htm formaggini susanna] [http://broadwaylili.ifrance.com/content/view/bando-di.htm bando di concorso a 500 agenti forestali] [http://yeeden.ifrance.com/img/styles/quadri-olii/ quadri olii xx secolo falsi autore] [http://tat-ooin.ifrance.com/resources/articles/prime-immagini.htm prime immagini e dettagli per rule of rose] [http://jdawsona.ifrance.com/data/lele/ lele] [http://igaros.ifrance.com/lib/arriva-millennium/ arriva millennium] [http://girlwho-is.ifrance.com/img/styles/fuoco-nel.htm fuoco nel fuoco da ascoltare] [http://noxuhax.ifrance.com/content/view/vendita-bomboniera.htm vendita bomboniera] [http://deviantrus.ifrance.com/topic/verusca/ verusca] [http://toofarfrommaybe.ifrance.com/view/new/kelly-madison/ kelly madison] [http://highbulp.ifrance.com/images/small/giochi-xbox/ giochi xbox download] [http://voltia.ifrance.com/content/view/sesso-con.htm sesso con culturiste] [http://voltia.ifrance.com/content/view/electric-chitarre.htm electric chitarre e bassi] [http://noxuhax.ifrance.com/content/view/telefonini-lg.htm telefonini lg c1100] [http://akmokanzen.ifrance.com/images/small/erotic-girl.htm erotic girl xxx com] [http://yeeden.ifrance.com/img/styles/epsom-and/ epsom and ewell] [http://noxuhax.ifrance.com/content/view/tony-e.htm tony e monia] [http://oiyaoi.ifrance.com/images/small/dvd-hdrw/ dvd hdrw720] [http://girlwho-is.ifrance.com/img/styles/apple-webcam.htm apple webcam] [http://voltia.ifrance.com/content/view/io-ti.htm io ti prendo come sposa] [http://yeeden.ifrance.com/img/styles/hammamet-alberghi/ hammamet alberghi e hotel] [http://singaporepets.ifrance.com/library/html/nuova-mercedes.htm nuova mercedes ml 280 auto nuove] [http://igaros.ifrance.com/lib/radiatori-elettrici/ radiatori elettrici] [http://tat-ooin.ifrance.com/resources/articles/viaggi-last.htm viaggi last minutes] [http://highbulp.ifrance.com/images/small/wireless-range/ wireless range extender] [http://oiyaoi.ifrance.com/images/small/ferari/ ferari] [http://tizolaa.ifrance.com/web/sharp-xv/ sharp xv z200] [http://kalian42.ifrance.com/text/directory/haplan/ haplan 2] [http://voltia.ifrance.com/content/view/topo-ratinator.htm topo ratinator] [http://demurediablo.ifrance.com/library/html/motorola-v/ motorola v3 confezione] [http://kalian42.ifrance.com/text/directory/colombino/ colombino] [http://tat-ooin.ifrance.com/resources/articles/hantaro-ham.htm hantaro ham ham] [http://noxuhax.ifrance.com/content/view/monica-piemonte.htm monica piemonte] [http://demurediablo.ifrance.com/library/html/hd-esterno/ hd esterno usb 250gb] [http://highbulp.ifrance.com/images/small/appunti-diritto/ appunti diritto] [http://highbulp.ifrance.com/images/small/canoe-kayak/ canoe kayak] [http://noxuhax.ifrance.com/content/view/il-cielo.htm il cielo su torino subsonica] [http://noxuhax.ifrance.com/content/view/z-verona.htm z3 verona] [http://demurediablo.ifrance.com/library/html/il-decalogo/ il decalogo sei] [http://toofarfrommaybe.ifrance.com/view/new/mus-t/ mus t] [http://deviantrus.ifrance.com/topic/the-best/ the best of 71] [http://oiyaoi.ifrance.com/images/small/la-coloniale/ la coloniale] [http://noxuhax.ifrance.com/content/view/sport-auricolari.htm sport auricolari] [http://broadwaylili.ifrance.com/content/view/router-modem.htm router modem adsl2] [http://tat-ooin.ifrance.com/resources/articles/blank-jones.htm blank jones] [http://yeeden.ifrance.com/img/styles/belkin-ups/ belkin ups] [http://toofarfrommaybe.ifrance.com/view/new/robowar/ robowar] [http://girlwho-is.ifrance.com/img/styles/taglia-forte.htm taglia forte] [http://noxuhax.ifrance.com/content/view/ipsema.htm ipsema] [http://oiyaoi.ifrance.com/images/small/kiki-pereira/ kiki pereira] [http://tizolaa.ifrance.com/web/ottobre/ ottobre 2005] [http://girlwho-is.ifrance.com/img/styles/bifid.htm bifid] [http://lordsander.ifrance.com/topic/araldo.htm araldo] [http://girlwho-is.ifrance.com/img/styles/eug.htm eug] [http://broadwaylili.ifrance.com/content/view/hp-psc.htm hp psc 1300] [http://speedofsoun.ifrance.com/text/directory/globen.htm globen] [http://lovereceier.ifrance.com/lib/nutrilon-pepti.htm nutrilon pepti 1] [http://deviantrus.ifrance.com/topic/nuevo-amor/ nuevo amor roberto orellana] [http://noxuhax.ifrance.com/content/view/guetta-money.htm guetta money] [http://highbulp.ifrance.com/images/small/cucce-per/ cucce per cane] [http://tizolaa.ifrance.com/web/dornod/ dornod] [http://lordsander.ifrance.com/topic/opel-tigra.htm opel tigra 1 3 cdti] [http://lordsander.ifrance.com/topic/twist-and.htm twist and go] [http://tat-ooin.ifrance.com/resources/articles/it-s.htm it s raining men] [http://kalian42.ifrance.com/text/directory/movie/ movie 4] [http://tizolaa.ifrance.com/web/lultima-carrozzella/ lultima carrozzella] [http://yeeden.ifrance.com/img/styles/telit-g/ telit g90] [http://tizolaa.ifrance.com/web/giornale-vanity/ giornale vanity fair] [http://speedofsoun.ifrance.com/text/directory/vier.htm vier] [http://kalian42.ifrance.com/text/directory/stampante-a/ stampante a3 color] [http://demurediablo.ifrance.com/library/html/scambio-auto/ scambio auto] [http://voltia.ifrance.com/content/view/la-domus.htm la domus aurea] [http://kalian42.ifrance.com/text/directory/bischoff-bernhard/ bischoff, bernhard] [http://toofarfrommaybe.ifrance.com/view/new/soluzione-della/ soluzione della seconda prova dell esame] [http://tat-ooin.ifrance.com/resources/articles/mario-lentini.htm mario lentini] [http://noxuhax.ifrance.com/content/view/www-cosenza.htm www cosenza turismo com] [http://kalian42.ifrance.com/text/directory/altoparlanti-creative/ altoparlanti creative inspire 5 1] [http://highbulp.ifrance.com/images/small/grossista-abbigliamento/ grossista abbigliamento] [http://demurediablo.ifrance.com/library/html/giler/ giler] [http://demurediablo.ifrance.com/library/html/fabio-cozzani/ fabio cozzani] [http://deviantrus.ifrance.com/topic/rebus-per/ rebus per un assassino] [http://speedofsoun.ifrance.com/text/directory/el-scan.htm el scan] [http://demurediablo.ifrance.com/library/html/bergamo-alberghi/ bergamo alberghi e hotel] [http://toofarfrommaybe.ifrance.com/view/new/carrozzine-baby/ carrozzine baby] [http://speedofsoun.ifrance.com/text/directory/soluzione-a.htm soluzione 2a prova maturita it] [http://demurediablo.ifrance.com/library/html/sm-v/ sm 913v] [http://akmokanzen.ifrance.com/images/small/tettone-video.htm tettone video] [http://jdawsona.ifrance.com/data/giovani-troia/ giovani troia] [http://lovereceier.ifrance.com/lib/kaja-paschalska.htm kaja paschalska] [http://igaros.ifrance.com/lib/dizionario-di/ dizionario di latino] [http://kalian42.ifrance.com/text/directory/impreza-/ impreza 2.0 t 16v awd sti] [http://tizolaa.ifrance.com/web/wildsnake-pinball/ wildsnake pinball soccer] [http://broadwaylili.ifrance.com/content/view/clisteri-gay.htm clisteri gay] [http://tat-ooin.ifrance.com/resources/articles/sigla-uefa.htm sigla uefa] [http://lovereceier.ifrance.com/lib/winbrick.htm winbrick] [http://lovereceier.ifrance.com/lib/panasonic-nv.htm panasonic nv vp 23] [http://lordsander.ifrance.com/topic/tino-almera.htm tino almera] [http://deviantrus.ifrance.com/topic/newporktimes/ newporktimes] [http://speedofsoun.ifrance.com/text/directory/cerca-stradario.htm cerca stradario] [http://deviantrus.ifrance.com/topic/stampanti-epson/ stampanti epson stylus photo] [http://voltia.ifrance.com/content/view/ipnosi.htm ipnosi] [http://voltia.ifrance.com/content/view/radeon-se.htm radeon 9800se 256mb] [http://tizolaa.ifrance.com/web/climatizzatore-panasonic/ climatizzatore panasonic] [http://broadwaylili.ifrance.com/content/view/negozi-in.htm negozi in franchising di calze e collant] [http://akmokanzen.ifrance.com/images/small/voli-santiago.htm voli santiago de compostela] [http://lordsander.ifrance.com/topic/fir-man.htm fir man] [http://girlwho-is.ifrance.com/img/styles/sound-of.htm sound of the sea] [http://speedofsoun.ifrance.com/text/directory/kompong-som.htm kompong som] [http://yeeden.ifrance.com/img/styles/agriturismo-bormio/ agriturismo bormio] [http://igaros.ifrance.com/lib/gx-cellulari/ gx25 cellulari] [http://jdawsona.ifrance.com/data/tv-color/ tv color 17 pollici] [http://jdawsona.ifrance.com/data/phaenton/ phaenton] [http://noxuhax.ifrance.com/content/view/stampante-aghi.htm stampante aghi 136] [http://singaporepets.ifrance.com/library/html/mns-com.htm mns com] [http://highbulp.ifrance.com/images/small/software-gestione/ software gestione desktop pocket pc] [http://voltia.ifrance.com/content/view/fiat-idea.htm fiat idea 1.3] [http://yeeden.ifrance.com/img/styles/mutuo-fondiario/ mutuo fondiario] [http://lovereceier.ifrance.com/lib/i-whant.htm i whant fly whit you] [http://oiyaoi.ifrance.com/images/small/diffusori-da/ diffusori da parete] [http://igaros.ifrance.com/lib/farrugia-franco/ farrugia franco] [http://akmokanzen.ifrance.com/images/small/blackang.htm blackang] [http://speedofsoun.ifrance.com/text/directory/www-scopami.htm www scopami it] [http://oiyaoi.ifrance.com/images/small/la-strada/ la strada di ognuno] [http://jdawsona.ifrance.com/data/bocelli-vivo/ bocelli vivo per lei] [http://lovereceier.ifrance.com/lib/il-prossimo.htm il prossimo uomo] [http://girlwho-is.ifrance.com/img/styles/ville-per.htm ville per vacanze in spagna] [http://akmokanzen.ifrance.com/images/small/ipod-mini.htm ipod mini black] [http://tizolaa.ifrance.com/web/preventivo-rc/ preventivo rc auto] [http://girlwho-is.ifrance.com/img/styles/opel-astra.htm opel astra station wagon] [http://tat-ooin.ifrance.com/resources/articles/cellulare-treo.htm cellulare treo] [http://lovereceier.ifrance.com/lib/acer-aspire.htm acer aspire wlmi 1362] [http://speedofsoun.ifrance.com/text/directory/mappa-praga.htm mappa praga] [http://igaros.ifrance.com/lib/blocchi-veicoli/ blocchi veicoli autocad] [http://oiyaoi.ifrance.com/images/small/glow/ glow] [http://igaros.ifrance.com/lib/dolce-lei/ dolce lei] [http://girlwho-is.ifrance.com/img/styles/porcellana-ceramica.htm porcellana ceramica altra arredamento] [http://broadwaylili.ifrance.com/content/view/hp.htm hp 8150] [http://yeeden.ifrance.com/img/styles/schede-audio/ schede audio terratec aureon 7 1] [http://lovereceier.ifrance.com/lib/lo-sgarro.htm lo sgarro] [http://igaros.ifrance.com/lib/villaggio-spagna/ villaggio spagna] [http://singaporepets.ifrance.com/library/html/monitor-belinea.htm monitor belinea crt 22] [http://singaporepets.ifrance.com/library/html/www-gougle.htm www gougle ti] [http://deviantrus.ifrance.com/topic/obiettivi-nikon/ obiettivi nikon 24-120mm] [http://voltia.ifrance.com/content/view/elledici-org.htm elledici org] [http://oiyaoi.ifrance.com/images/small/manuela-arcuri/ manuela arcuri porno] [http://voltia.ifrance.com/content/view/legge-articolo.htm legge articolo ex 23 85 95] [http://lovereceier.ifrance.com/lib/spot-nike.htm spot nike 2004] [http://oiyaoi.ifrance.com/images/small/taglio-capelli/ taglio capelli] [http://tizolaa.ifrance.com/web/epson-stylus/ epson stylus photo 870] [http://speedofsoun.ifrance.com/text/directory/breath-eazy.htm breath eazy] [http://tat-ooin.ifrance.com/resources/articles/il-nostro.htm il nostro pane quotidiano] [http://igaros.ifrance.com/lib/becker-traffic/ becker traffic pro 7945] [http://tizolaa.ifrance.com/web/power-system/ power system sas] [http://yeeden.ifrance.com/img/styles/felpa-napoli/ felpa napoli] [http://igaros.ifrance.com/lib/hitachi/ hitachi 250] [http://tizolaa.ifrance.com/web/ossessioni/ ossessioni] [http://speedofsoun.ifrance.com/text/directory/sultanes.htm sultanes] [http://lordsander.ifrance.com/topic/baan-specialist.htm baan specialist (regione lombardia - milano provincia)] [http://deviantrus.ifrance.com/topic/suburbia-tracklist/ suburbia tracklist] [http://lovereceier.ifrance.com/lib/abies.htm abies] [http://noxuhax.ifrance.com/content/view/baron-de.htm baron de l] [http://jdawsona.ifrance.com/data/guy-cloutier/ guy cloutier] [http://deviantrus.ifrance.com/topic/il-prezzo/ il prezzo della liberta] [http://speedofsoun.ifrance.com/text/directory/video-free.htm video free eros] [http://demurediablo.ifrance.com/library/html/bahama-hotel/ bahama hotel] [http://highbulp.ifrance.com/images/small/masti/ masti] [http://noxuhax.ifrance.com/content/view/pannelli-isolanti.htm pannelli isolanti] [http://speedofsoun.ifrance.com/text/directory/nad-t.htm nad t562] [http://highbulp.ifrance.com/images/small/via-la/ via la cellulite] [http://akmokanzen.ifrance.com/images/small/bellezze-vip.htm bellezze vip] [http://highbulp.ifrance.com/images/small/heaven-adams/ heaven adams] [http://igaros.ifrance.com/lib/gigidag/ gigidag] [http://lordsander.ifrance.com/topic/www-tommyvee.htm www tommyvee com] {{Template:split-review}}
{{task}}
{{task}}


Line 65: Line 65:
char *p = (char *) string;
char *p = (char *) string;
while (*p != '\0') length ;
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 ]] (AKA [[C plus plus 98|C 98]]):
'''Standard:''' [[ISO C plus plus|ISO C++]] (AKA [[C plus plus 98|C++98]]):


'''Compiler:''' g 4.0.2
'''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 18:08, 19 August 2007

This task has has been split off from another task. Its programming examples are in need of review to ensure that they fit the requirements of the new task.
Task
String Byte Length
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

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;
 }

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

 CREATE s ," Hello world" \ create string "s"
 s C@ ( -- length )

Haskell

Interpreter: GHCi 6.6, Hugs

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"