String Character Length: Difference between revisions
Content added Content deleted
mNo edit summary |
m (Stupid case-sensitivity.) |
||
(63 intermediate revisions by 15 users not shown) | |||
Line 1: | Line 1: | ||
#REDIRECT [[String length]] |
|||
[http://students.hsc.unt.edu/housing/item.cfm?type=2892 cheap rivotril] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=95 kyocera ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=29 cheap cialis] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=74 ultracet online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/levitra_8223.htm levitra] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30361 free kyocera ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2908 free music ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=88 free free ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a35 free verizon ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=31 cheap soma] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=204 cheap ortho] [http://library.cshl.edu/wp/vb/member.php?u=1362 wellbutrin online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30310 cheap tenuate] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=121 free real ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2902 nextel ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1356 order paxil] [http://students.hsc.unt.edu/housing/item.cfm?type=2905 free motorola ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1344 xanax online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=798 cheap lipitor] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30355 free punk ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=87 sony ericsson ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=118 cool ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2913 free sonyericsson ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3735 free mtv ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=63 cheap albuterol] [http://students.hsc.unt.edu/housing/item.cfm?type=2910 polyphonic ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30298 order lisinopril] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=236 free tracfone ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2877 prozac online] [http://wc1.worldcrossing.com/WebX/.1de609df cheap ambien] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=779 clonazepam online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=90 zanaflex online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=54 buy lisinopril] [http://library.cshl.edu/wp/vb/member.php?u=1358 hydrocodone online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=127 soma online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=768 fioricet online] [http://wc1.worldcrossing.com/WebX/.1de60a26 sharp ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30358 free midi ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/paxil_4058.htm cheap paxil] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30266 cheap lorazepam] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=104 free motorola ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1a mtv ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30323 flexeril online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3770 alltel ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=83 didrex online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=21 soma] [http://wc1.worldcrossing.com/WebX/.1de60a31 buy zanaflex] [http://students.hsc.unt.edu/housing/item.cfm?type=2920 midi ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=140 vicodin online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30365 mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de609ed buy hoodia] [http://students.hsc.unt.edu/housing/item.cfm?type=2865 paxil online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=114 sony ericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f2 online meridia] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30268 xenical online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=122 rivotril online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=2694 valium] [http://students.hsc.unt.edu/housing/item.cfm?type=2853 cheap fioricet] [http://library.cshl.edu/wp/vb/member.php?u=1354 alprazolam online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=209 xenical] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=65 buy rivotril] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=101 mp3 ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=95 kyocera ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a21 paxil online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/musicringtones_8033.htm music ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3706 wellbutrin online] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=65 zoloft online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/sonyericssonringtones_2032.htm free sonyericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=137 cheap valium] [http://wc1.worldcrossing.com/WebX/.1de609e3 clomid online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=804 cheap vigrx] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=803 cheap lortab] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30354 alltel ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=120 midi ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=94 buy flexeril] [http://library.cshl.edu/wp/vb/member.php?u=1382 free cingular ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3733 wwe ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3736 soma online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=766 cheap carisoprodol] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=161 albuterol online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30312 cheap ortho] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=101 buy meridia] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3716 buy diethylpropion] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=820 free real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=89 free funny ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=86 cheap fioricet] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=56 buy ultracet] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=133 tracfone ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/funnyringtones_5351.htm free funny ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=62 order clomid] [http://students.hsc.unt.edu/housing/item.cfm?type=2906 free samsung ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30296 clomid online] [http://wc1.worldcrossing.com/WebX/.1de60a17 lipitor online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=801 online ortho] [http://wc1.worldcrossing.com/WebX/.1de609ea free free ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30315 buy lortab] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=22 valium online] [http://library.cshl.edu/wp/vb/member.php?u=1361 xenical online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=763 buy soma] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3721 mp3 ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a33 cheap prozac] [http://wc1.worldcrossing.com/WebX/.1de609dc buy albuterol] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=189 cheap lipitor] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30350 sagem ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30277 cyclobenzaprine online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=117 cheap propecia] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=106 free samsung ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=66 but levitra] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3746 cheap ambien] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/alltelringtones_474.htm alltel ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/verizonringtones_8798.htm free verizon ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1381 polyphonic ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=56 cialis online] [http://students.hsc.unt.edu/housing/item.cfm?type=2924 ericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de609fb ortho online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=94 free wwe ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=171 clomid online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/mpringtones_1668.htm free mp3 ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30316 order vigrx] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3744 buy clonazepam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=200 nexium] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=33 buy adipex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=76 cialis] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=178 ericsson ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=86 free qwest ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=109 verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30295 cheap sildenafil] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/adipex_547.htm cheap adipex] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=839 free kyocera ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/nexium_2418.htm nexium online] [http://wc1.worldcrossing.com/WebX/.1de609f3 midi ringtones] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=827 free cingular ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f7 nextel ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a20 nexium online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=195 free mono ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=77 cingular ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=85 buy tenuate] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3734 sony ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30265 order ambien] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=170 cingular ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30332 tracfone ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=53 cheap xenical] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3759 flexeril online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=55 zoloft online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=169 cialis] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=78 buy hoodia] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=213 prozac online] [http://students.hsc.unt.edu/housing/item.cfm?type=2849 valium] [http://students.hsc.unt.edu/housing/item.cfm?type=2880 albuterol online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3717 hgh online] [http://wc1.worldcrossing.com/WebX/.1de60a00 rivotril online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=52 xanax online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/cyclobenzaprine_72.htm cheap cyclobenzaprine] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=175 diazepam online] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=39 cheap cialis] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=66 flexeril online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30345 sprint ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=96 zyban online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=99 tracfone ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=32 valium online] [http://students.hsc.unt.edu/housing/item.cfm?type=2867 cheap hydrocodone] [http://students.hsc.unt.edu/housing/item.cfm?type=2872 online cyclobenzaprine] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=222 vigrx online] [http://students.hsc.unt.edu/housing/item.cfm?type=2875 propecia online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30320 rivotril online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30253 norco online] [http://library.cshl.edu/wp/vb/member.php?u=1369 free ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3769 free sony ericsson ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2889 cheap vigrx] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=74 free mp3 ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2925 free mtv ringtones] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=828 sagem ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=72 tracfone ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=96 sony ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=188 levitra online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=46 online nexium] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=51 ambien] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=82 free tracfone ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=40 hydrocodone online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/ambien_7869.htm ambien online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3737 but phentermine] [http://library.cshl.edu/wp/vb/member.php?u=1347 cheap cialis] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=59 buy ortho] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=837 free midi ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=46 alprazolam online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=83 order lipitor] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=44 wellbutrin online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=60 pharmacy online online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30339 samsung ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3771 free cool ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=83 funny ringtones] [http://wc1.worldcrossing.com/WebX/.1de609dd free alltel ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=26 fioricet online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=97 nokia ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=205 paxil online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=88 lortab online] [http://wc1.worldcrossing.com/WebX/.1de60a34 free sony ericsson ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=211 polyphonic ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30308 cheap lipitor] [http://students.hsc.unt.edu/housing/item.cfm?type=2886 order ortho] {{task}} |
|||
{{Template:split-review}} |
|||
In this task, the goal is to find the <em>character</em> length of a string. This means encodings like [[UTF-8]] need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. |
|||
For byte length, see [[String Byte Length]]. |
|||
==[[ActionScript]]== |
|||
[[Category:ActionScript]] |
|||
myStrVar.length() |
|||
==[[Ada]]== |
|||
[[Category:Ada]] |
|||
'''Compiler:''' GCC 4.1.2 |
|||
Str : String := "Hello World"; |
|||
Length : constant Natural := Str'Length; |
|||
==[[AppleScript]]== |
|||
[[Category:AppleScript]] |
|||
count of "Hello World" |
|||
==[[AWK]]== |
|||
[[Category:AWK]] |
|||
From within any code block: |
|||
w=length("Hello, world!") # static string example |
|||
x=length("Hello," s " world!") # dynamic string example |
|||
y=length($1) # input field example |
|||
z=length(s) # variable name example |
|||
Ad hoc program from command line: |
|||
echo "Hello, world!" | awk '{print length($0)}' |
|||
From executable script: (prints for every line arriving on stdin) |
|||
#!/usr/bin/awk -f |
|||
{print"The length of this line is "length($0)} |
|||
==[[C]]== |
|||
[[Category:C]] |
|||
'''Standard:''' [[ANSI C]] (AKA [[C89]]): |
|||
'''Compiler:''' GCC 3.3.3 |
|||
#include <string.h> |
|||
int main(void) |
|||
{ |
|||
const char *string = "Hello, world!"; |
|||
size_t length = strlen(string); |
|||
return 0; |
|||
} |
|||
or by hand: |
|||
int main(void) |
|||
{ |
|||
const char *string = "Hello, world!"; |
|||
size_t length = 0; |
|||
char *p = (char *) string; |
|||
while (*p != '\0') length ; |
|||
return 0; |
|||
} |
|||
or (for arrays of char only) |
|||
#include <stdlib.h> |
|||
int main(void) |
|||
{ |
|||
char const s[] = "Hello, world!"; |
|||
size_t length = sizeof s - 1; |
|||
return 0; |
|||
} |
|||
For wide character strings (usually Unicode): |
|||
#include <stdio.h> |
|||
#include <wchar.h> |
|||
int main(void) |
|||
{ |
|||
wchar_t *s = L"\x304A\x306F\x3088\x3046"; /* Japanese hiragana ohayou */ |
|||
size_t length; |
|||
length = wcslen(s); |
|||
printf("Length in characters = %d\n", length); |
|||
printf("Length in bytes = %d\n", sizeof(s) * sizeof(wchar_t)); |
|||
return 0; |
|||
} |
|||
==[[C plus plus|C ]]== |
|||
[[Category:C plus plus|C ]] |
|||
'''Standard:''' [[ISO C plus plus|ISO C ]] (AKA [[C plus plus 98|C 98]]): |
|||
'''Compiler:''' g 4.0.2 |
|||
#include <string> // note: '''not''' <string.h> |
|||
int main() |
|||
{ |
|||
std::string s = "Hello, world!"; |
|||
// Always in characters == bytes since sizeof(char) == 1 |
|||
std::string::size_type length = s.length(); // option 1: In Characters/Bytes |
|||
std::string::size_type size = s.size(); // option 2: In Characters/Bytes |
|||
} |
|||
For wide character strings: |
|||
#include <string> |
|||
int main() |
|||
{ |
|||
std::wstring s = L"\u304A\u306F\u3088\u3046"; |
|||
std::wstring::size_type length = s.length(); |
|||
} |
|||
==[[C sharp|C#]]== |
|||
[[Category:C sharp|C#]] |
|||
'''Platform:''' [[.NET]] |
|||
'''Language Version:''' 1.0 |
|||
string s = "Hello, world!"; |
|||
int clength = s.Length; // In characters |
|||
int blength = System.Text.Encoding.GetBytes(s).length; // In Bytes. |
|||
==[[Clean]]== |
|||
[[Category:Clean]] |
|||
Clean Strings are unboxed arrays of characters. Characters are always a single byte. The function size returns the number of elements in an array. |
|||
import StdEnv |
|||
strlen :: String -> Int |
|||
strlen string = size string |
|||
Start = strlen "Hello, world!" |
|||
==[[ColdFusion]]== |
|||
[[Category:ColdFusion]] |
|||
#len("Hello World")# |
|||
==[[Common Lisp]]== |
|||
[[Category:Common Lisp]] |
|||
(length "Hello World") |
|||
==[[Component Pascal]]== |
|||
[[Category:Component Pascal]] |
|||
LEN("Hello, World!") |
|||
==[[E]]== |
|||
[[Category:E]] |
|||
"Hello World".size() |
|||
==[[Forth]]== |
|||
[[Category:Forth]] |
|||
'''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 most commonly used characters are represented by one 16-bit value, while rarer ones like some mathematical symbols are represented by two. |
|||
The length method of String objects gives the number of 16-bit values used to encode a string. |
|||
String s = "Hello, world!"; |
|||
int length = s.length(); |
|||
Since Java 1.5, the actual number of characters can be determined by calling the codePointCount method. |
|||
String str = "\uD834\uDD2A"; //U 1D12A |
|||
int length1 = str.length(); //2 |
|||
int length2 = str.codePointCount(0, str.length()); //1 |
|||
==[[JavaScript]]== |
|||
[[Category:JavaScript]] |
|||
JavaScript encodes strings in UTF-16, which represents each character with one or two 16-bit values. The most commonly used characters are represented by one 16-bit value, while rarer ones like some mathematical symbols are represented by two. |
|||
JavaScript has no built-in way to determine how many characters are in a string. However, if the string only contains commonly used characters, the number of characters will be equal to the number of 16-bit values used to represent the characters. |
|||
var str1 = "Hello, world!"; |
|||
var len1 = str1.length; //13 |
|||
var str2 = "\uD834\uDD2A"; //U 1D12A represented by a UTF-16 surrogate pair |
|||
var len2 = str2.length; //2 |
|||
==[[JudoScript]]== |
|||
[[Category:JudoScript]] |
|||
//Store length of hello world in length and print it |
|||
. length = "Hello World".length(); |
|||
==[[Lua]]== |
|||
[[Category:Lua]] |
|||
'''Interpreter:''' [[Lua]] 5.0 or later. |
|||
string="Hello world" |
|||
length=#string |
|||
==[[mIRC Scripting Language]]== |
|||
[[Category:mIRC Scripting Language]] |
|||
'''Interpreter:''' [[mIRC]] |
|||
alias stringlength { echo -a Your Name is: $len($$?="Whats your name") letters long! } |
|||
==[[OCaml]]== |
|||
[[Category:OCaml]] |
|||
'''Interpreter'''/'''Compiler:''' [[Ocaml]] 3.09 |
|||
String.length "Hello world";; |
|||
==[[Perl]]== |
|||
[[Category:Perl]] |
|||
'''Interpreter:''' [[Perl]] any 5.X |
|||
my $length = length "Hello, world!"; |
|||
==[[PHP]]== |
|||
[[Category:PHP]] |
|||
$length = strlen('Hello, world!'); |
|||
==[[PL/SQL|PL/SQL]]== |
|||
[[Category:PL/SQL|PL/SQL]] |
|||
DECLARE |
|||
string VARCHAR2( 50 ) := 'Hello, world!'; |
|||
stringlength NUMBER; |
|||
BEGIN |
|||
stringlength := length( string ); |
|||
END; |
|||
==[[Python]]== |
|||
[[Category:Python]] |
|||
'''Interpreter:''' [[Python]] 2.4 |
|||
length = len("The length of this string will be determined") |
|||
==[[Ruby]]== |
|||
[[Category:Ruby]] |
|||
'''Library:''' [[active_support]] |
|||
require 'active_support' |
|||
puts "Hello World".chars.length |
|||
==[[Scheme]]== |
|||
[[Category:Scheme]] |
|||
(string-length "Hello world") |
|||
==[[Seed7]]== |
|||
[[Category:Seed7]] |
|||
length("Hello, world!") |
|||
==[[Smalltalk]]== |
|||
[[Category:Smalltalk]] |
|||
string := 'Hello, world!". |
|||
string size. |
|||
==[[Standard ML]]== |
|||
[[Category:Standard ML]] |
|||
'''Interpreter:''' [[Standard ML of New Jersey | SML/NJ]] 110.60, [[Moscow ML]] 2.01 (January 2004) |
|||
'''Compiler:''' [[MLton]] 20061107 |
|||
val strlen = size "Hello, world!"; |
|||
==[[Tcl]]== |
|||
[[Category:Tcl]] |
|||
Basic version: |
|||
string length "Hello, world!" |
|||
or more elaborately, needs '''Interpreter''' any 8.X. Tested on 8.4.12. |
|||
fconfigure stdout -encoding utf-8; #So that Unicode string will print correctly |
|||
set s1 "hello, world" |
|||
set s2 "\u304A\u306F\u3088\u3046" |
|||
puts [format "length of \"%s\" in characters is %d" $s1 [string length $s1]] |
|||
puts [format "length of \"%s\" in characters is %d" $s2 [string length $s2]] |
|||
==[[UNIX Shell]]== |
|||
[[Category:UNIX Shell]] |
|||
With external utilities: |
|||
'''Interpreter:''' any bourne shell |
|||
string='Hello, world!' |
|||
length=`echo -n "$string" | wc -c | tr -dc '0-9'` |
|||
echo $length # if you want it printed to the terminal |
|||
With SUSv3 parameter expansion modifier: |
|||
'''Interpreter:''' [[Almquist SHell]] (NetBSD 3.0), [[Bourne Again SHell]] 3.2, [[Korn SHell]] (5.2.14 99/07/13.2), [[Z SHell]] |
|||
string='Hello, world!' |
|||
length="${#string}" |
|||
echo $length # if you want it printed to the terminal |
|||
==[[VBScript]]== |
|||
[[Category:VBScript]] |
|||
Len(string|varname) |
|||
Returns the length of the string|varname |
|||
Returns null if string|varname is null |
|||
==[[xTalk]]== |
|||
[[Category:xTalk]] |
|||
'''Interpreter:''' HyperCard |
|||
put the length of "Hello World" |
|||
or |
|||
put the number of characters in "Hello World" |
Latest revision as of 19:31, 19 January 2008
Redirect to: