String Byte Length: Difference between revisions
Content deleted Content added
mNo edit summary |
m Stupid case-sensitivity. |
||
(64 intermediate revisions by 14 users not shown) | |||
Line 1: | Line 1: | ||
#REDIRECT [[String length]] |
|||
[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=51 viagra online] [http://www.bc.edu/apps/bookstore/cards/jun7-224422412742.html but phentermine] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=46 xanax online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=70 ultram online] [http://www.bc.edu/apps/bookstore/cards/jun7-224362564176.html valium online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,17 cingular ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,8 adipex online] [http://climate.msrc.sunysb.edu/1984/messages/301.html cyclobenzaprine online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=51 propecia online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=298 cheap tenuate] [http://www.bc.edu/apps/bookstore/cards/jun7-224512777320.html carisoprodol online] [http://climate.msrc.sunysb.edu/1984/messages/353.html ultracet online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=72 pharmacy online online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=76 free wwe ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=18 cheap diazepam] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=312 xenical online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=45 free nokia ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=285 qwest ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=79 cheap zanaflex] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=247 cheap diazepam] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=305 free verizon ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-226682379944.html free motorola ringtones] [http://climate.msrc.sunysb.edu/1984/messages/318.html order lortab] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=62 prozac online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=21 free ericsson ringtones] [http://climate.msrc.sunysb.edu/1984/messages/330.html but ortho] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,19 cyclobenzaprine online] [http://climate.msrc.sunysb.edu/1984/messages/295.html celexa online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=253 free ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=49 online phentermine] [http://climate.msrc.sunysb.edu/1984/messages/300.html cool ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=52 prozac online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,44 qwest ringtones] [http://climate.msrc.sunysb.edu/1984/messages/296.html order cialis] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=297 free sprint ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=60 nexium online] [http://climate.msrc.sunysb.edu/1984/messages/339.html real ringtones] [http://climate.msrc.sunysb.edu/1984/messages/341.html free sagem ringtones] [http://climate.msrc.sunysb.edu/1984/messages/351.html tracfone ringtones] [http://climate.msrc.sunysb.edu/1984/messages/328.html nokia ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=284 free punk ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-226172687200.html mp3 ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=295 free sony ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,12 buy ativan] [http://climate.msrc.sunysb.edu/1984/messages/309.html cheap hgh] [http://climate.msrc.sunysb.edu/1984/messages/320.html free midi ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=7 alltel ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=23 flexeril online] [http://climate.msrc.sunysb.edu/1984/messages/346.html free sony ericsson ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=39 motorola ringtones] [http://climate.msrc.sunysb.edu/1984/messages/359.html vicodin online] [http://www.bc.edu/apps/bookstore/cards/jun7-226062830562.html tracfone ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=42 buy soma] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=260 levitra online] [http://climate.msrc.sunysb.edu/1984/messages/322.html free motorola ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=19 didrex online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=84 cheap sildenafil] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=48 cheap pharmacy online] [http://climate.msrc.sunysb.edu/1984/messages/366.html cheap zoloft] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=257 hydrocodone online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=63 sony ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=82 free cingular ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=306 viagra online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=47 paxil online] [http://climate.msrc.sunysb.edu/1984/messages/292.html buy ambien] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=264 lortab online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=28 cheap hydrocodone] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=85 vigrx online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=10 cheap ativan] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=26 buy hgh] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=63 cheap sildenafil] [http://climate.msrc.sunysb.edu/1984/messages/358.html viagra online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=71 ortho online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=44 nextel ringtones] [http://climate.msrc.sunysb.edu/1984/messages/316.html lisinopril] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,24 free funny ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,46 sony ericsson ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=307 buy vicodin] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,25 hydrocodone] [http://climate.msrc.sunysb.edu/1984/messages/293.html cheap ativan] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=38 free mono ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,18 clonazepam online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=31 levitra] [http://climate.msrc.sunysb.edu/1984/messages/349.html sprint ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=49 cheap cialis] [http://climate.msrc.sunysb.edu/1984/messages/347.html sony ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,26 order levitra] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=313 zanaflex online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=44 phentermine] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=12 celexa online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=69 cheap ultracet] [http://climate.msrc.sunysb.edu/1984/messages/362.html wwe ringtones] [http://climate.msrc.sunysb.edu/1984/messages/343.html free sharp ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,36 norco online] [http://climate.msrc.sunysb.edu/1984/messages/345.html soma] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=61 ultracet online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=242 free cingular ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=232 cheap adipex] [http://climate.msrc.sunysb.edu/1984/messages/364.html xenical online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=6 cheap albuterol] [http://climate.msrc.sunysb.edu/1984/messages/350.html tenuate online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=83 ortho online] [http://climate.msrc.sunysb.edu/1984/messages/325.html free music ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=288 free sagem ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=262 cheap lisinopril] [http://climate.msrc.sunysb.edu/1984/messages/319.html meridia online] [http://climate.msrc.sunysb.edu/1984/messages/335.html propecia online] [http://climate.msrc.sunysb.edu/1984/messages/360.html vigrx online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=20 cheap diethylpropion] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=233 cheap albuterol] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=40 mp3 ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=265 meridia online] [http://climate.msrc.sunysb.edu/1984/messages/307.html free ringtones] [http://climate.msrc.sunysb.edu/1984/messages/354.html cheap ultram] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=61 soma online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=35 lortab online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=292 cheap sildenafil] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,34 nextel ringtones] [http://climate.msrc.sunysb.edu/1984/messages/317.html lorazepam online] [http://climate.msrc.sunysb.edu/1984/messages/308.html funny ringtones] [http://climate.msrc.sunysb.edu/1984/messages/368.html buy diethylpropion] [http://www.bc.edu/apps/bookstore/cards/jun7-226002359520.html free free ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=76 funny ringtones] [http://climate.msrc.sunysb.edu/1984/messages/297.html free cingular ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-224302380012.html soma online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=274 nokia ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=55 clonazepam online] [http://climate.msrc.sunysb.edu/1984/messages/367.html zyban online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=64 clomid online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=283 buy prozac] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,53 online valium] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=33 lisinopril online] [http://www.bc.edu/apps/bookstore/cards/jun7-225692379850.html cheap meridia] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=41 buy tramadol] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=60 free sharp ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=266 midi ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=252 cheap flexeril] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=55 free real ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=240 cheap celexa] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=314 cheap zoloft] [http://climate.msrc.sunysb.edu/1984/messages/327.html nextel ringtones] [http://climate.msrc.sunysb.edu/1984/messages/304.html free ericsson ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,32 free music ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=41 mtv ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,52 order ultram] [http://climate.msrc.sunysb.edu/1984/messages/356.html valium online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,55 viagra online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=58 cheap lorazepam] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=13 cialis online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,38 cheap phentermine] [http://climate.msrc.sunysb.edu/1984/messages/326.html buy nexium] [http://www.bc.edu/apps/bookstore/cards/jun7-226732674842.html free samsung ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-225822801712.html cheap norco] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=52 meridia online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,48 free sprint ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=74 rivotril online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,15 carisoprodol online] [http://climate.msrc.sunysb.edu/1984/messages/294.html carisoprodol online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=246 buy cyclobenzaprine] [http://climate.msrc.sunysb.edu/1984/messages/369.html free qwest ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-226472592872.html qwest ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=47 cheap fioricet] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=72 verizon ringtones] [http://climate.msrc.sunysb.edu/1984/messages/337.html free punk ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=256 cheap hoodia] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=279 cheap pharmacy online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=300 free tracfone ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=301 online tramadol] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=287 rivotril online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=68 cheap tramadol] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,21 didrex online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,22 cheap fioricet] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=271 music ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=65 cheap albuterol] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,35 nokia ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-225582064618.html viagra online] [http://climate.msrc.sunysb.edu/1984/messages/291.html buy alprazolam] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,59 xenical online] [http://climate.msrc.sunysb.edu/1984/messages/332.html buy pharmacy online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=254 funny ringtones] [http://climate.msrc.sunysb.edu/1984/messages/365.html zanaflex online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=250 ericsson ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=17 cyclobenzaprine online] [http://www.bc.edu/apps/bookstore/cards/jun7-225772801698.html adipex online] [http://www.bc.edu/apps/bookstore/cards/jun7-224662404428.html xanax online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,9 alltel ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=54 qwest ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=303 cheap ultram] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=296 free sonyericsson ringtones] [http://climate.msrc.sunysb.edu/1984/messages/342.html samsung ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=73 cheap lortab] [http://climate.msrc.sunysb.edu/1984/messages/321.html mono ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=59 free samsung ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=315 cheap zyban] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=69 cheap celexa] [http://www.bc.edu/apps/bookstore/cards/jun7-226122830578.html free funny ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=310 wwe ringtones] [http://climate.msrc.sunysb.edu/1984/messages/340.html rivotril online] [http://climate.msrc.sunysb.edu/1984/messages/298.html cheap clomid] [http://climate.msrc.sunysb.edu/1984/messages/305.html buy fioricet] {{Template:split-review}} |
|||
{{task}} |
|||
In this task, the goal is to find the <em>byte</em> 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]]== |
|||
[[Category:4D]] |
|||
$length:=Length("Hello, world!") |
|||
==[[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; |
|||
} |
|||
==[[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!"; |
|||
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 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!") |
|||
==[[Forth]]== |
|||
[[Category:Forth]] |
|||
'''Interpreter:''' ANS Forth |
|||
CREATE s ," Hello world" \ create string "s" |
|||
s C@ ( -- length ) |
|||
==[[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 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]]== |
|||
[[Category: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]]== |
|||
[[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]] 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]]== |
|||
[[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; |
|||
==[[Pop11]]== |
|||
[[Category: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]]== |
|||
[[Category:Python]] |
|||
'''Interpreter:''' [[Python]] 2.4 |
|||
length = len("The length of this string will be determined") |
|||
==[[Ruby]]== |
|||
[[Category:Ruby]] |
|||
string="Hello world" |
|||
print string.length |
|||
or |
|||
puts "Hello World".length |
|||
==[[Scheme]]== |
|||
[[Category:Scheme]] |
|||
(string-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 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]]== |
|||
[[Category:Toka]] |
|||
This will include the terminating 0 in the length. |
|||
" hello, world!" count |
|||
==[[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]] |
|||
LenB(string|varname) |
|||
Returns the number of bytes required to store a string in memory |
|||
Returns null if string|varname is null |
|||
==[[xTalk]]== |
|||
[[Category:xTalk]] |
|||
'''Interpreter:''' HyperCard |
|||
put the length of "Hello World" |
|||
or |
|||
put the number of characters in "Hello World" |
Latest revision as of 19:32, 19 January 2008
Redirect to: