String Character Length: Difference between revisions
Content deleted Content added
mNo edit summary |
m Stupid case-sensitivity. |
||
(65 intermediate revisions by 15 users not shown) | |||
Line 1: | Line 1: | ||
#REDIRECT [[String length]] |
|||
[http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30258 cheap vicodin] [http://students.hsc.unt.edu/housing/item.cfm?type=2858 viagra online] [http://library.cshl.edu/wp/vb/member.php?u=1383 free sagem ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a33 prozac online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30346 music ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a19 mp3 ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2857 ativan online] [http://library.cshl.edu/wp/vb/member.php?u=1355 but clonazepam] [http://wc1.worldcrossing.com/WebX/.1de609f1 lortab online] [http://wc1.worldcrossing.com/WebX/.1de609f8 free nokia ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30335 free nextel ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/valium_6454.htm cheap valium] [http://students.hsc.unt.edu/housing/item.cfm?type=2874 cheap ultracet] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3710 clomid online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3773 kyocera ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1354 alprazolam online] [http://library.cshl.edu/wp/vb/member.php?u=1374 free qwest ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/soma_5561.htm cheap soma] [http://students.hsc.unt.edu/housing/item.cfm?type=2888 lortab online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30237 valium online] [http://wc1.worldcrossing.com/WebX/.1de60a0c buy wellbutrin] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/cingularringtones_7013.htm cingular ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3772 midi ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a14 jazz ringtones] [http://wc1.worldcrossing.com/WebX/.1de609ff free real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=125 sharp ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=235 online tenuate] [http://wc1.worldcrossing.com/WebX/.1de609ee but hydrocodone] [http://students.hsc.unt.edu/housing/item.cfm?type=2899 free tracfone ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=196 motorola ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3711 cheap lisinopril] [http://students.hsc.unt.edu/housing/item.cfm?type=2890 zanaflex] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=204 cheap ortho] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=184 hoodia] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=128 free sony ericsson ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=181 free ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2864 clonazepam online] [http://students.hsc.unt.edu/housing/item.cfm?type=2892 cheap rivotril] [http://library.cshl.edu/wp/vb/member.php?u=1370 tracfone ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/fioricet_2815.htm users.wpi.edu/~dance/blahdocs/uploads/ |
|||
] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=195 mono ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=188 levitra online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/tracfoneringtones_5328.htm free tracfone ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3713 tenuate online] [http://students.hsc.unt.edu/housing/item.cfm?type=2850 phentermine online] [http://wc1.worldcrossing.com/WebX/.1de60a11 diethylpropion online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30364 free ericsson ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3746 ambien online] [http://wc1.worldcrossing.com/WebX/.1de609fb order ortho] [http://wc1.worldcrossing.com/WebX/.1de60a12 free ericsson ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2884 cheap celexa] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30331 free free ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30230 cheap tramadol] [http://students.hsc.unt.edu/housing/item.cfm?type=2859 cheap meridia] [http://students.hsc.unt.edu/housing/item.cfm?type=2870 xenical online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30307 cheap zoloft] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/hydrocodone_3335.htm hydrocodone online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=174 order cyclobenzaprine] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3719 free nokia ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1351 buy adipex] [http://students.hsc.unt.edu/housing/item.cfm?type=2909 verizon ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=208 cheap phentermine] [http://students.hsc.unt.edu/housing/item.cfm?type=2915 free mono ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30353 free mono ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a0e celexa online] [http://students.hsc.unt.edu/housing/item.cfm?type=2883 lipitor online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/alltelringtones_474.htm free alltel ringtones] [http://wc1.worldcrossing.com/WebX/.1de609dd alltel ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/clonazepam_4321.htm clonazepam online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=144 xanax online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=148 order zyban] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=119 free punk ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2871 cheap wellbutrin] [http://students.hsc.unt.edu/housing/item.cfm?type=2866 cheap levitra] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30298 lisinopril online] [http://library.cshl.edu/wp/vb/member.php?u=1352 buy norco] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=124 samsung ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1353 vicodin] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=135 ultracet online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3700 online norco] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30308 lipitor online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30315 lortab online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30310 tenuate online] [http://users.wpi.edu/~dance/blahdocs/uploads/nextelringtones_5134.htm nextel ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/lorazepam_17.htm cheap lorazepam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=199 free music ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=112 but ortho] [http://library.cshl.edu/wp/vb/member.php?u=1361 xenical online] [http://students.hsc.unt.edu/housing/item.cfm?type=2855 diazepam online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=68 buy adipex] [http://users.wpi.edu/~dance/blahdocs/uploads/samsungringtones_3147.htm free samsung ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/carisoprodol_7292.htm cheap carisoprodol] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30297 albuterol online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=162 free alltel ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3702 paxil online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3758 buy rivotril] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30263 levitra online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=142 wellbutrin] [http://library.cshl.edu/wp/vb/member.php?u=1357 levitra online] [http://wc1.worldcrossing.com/WebX/.1de609ea free free ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30314 pharmacy online online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30240 carisoprodol online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/tramadol_3245.htm buy tramadol] [http://wc1.worldcrossing.com/WebX/.1de609e6 cyclobenzaprine online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=103 mono ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30248 ativan online] [http://library.cshl.edu/wp/vb/member.php?u=1385 free sony ericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a22 cheap phentermine] [http://students.hsc.unt.edu/housing/item.cfm?type=2901 mp3 ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3769 free sony ericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=127 soma online] [http://library.cshl.edu/wp/vb/member.php?u=1349 viagra online] [http://wc1.worldcrossing.com/WebX/.1de60a2c but ultram] [http://wc1.worldcrossing.com/WebX/.1de60a10 didrex online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=111 norco online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=224 free sagem ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30345 free sprint ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=76 cialis] [http://wc1.worldcrossing.com/WebX/.1de60a05 sprint ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=234 sprint ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1381 free polyphonic ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2873 nexium online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=92 hydrocodone online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=226 cheap tramadol] [http://students.hsc.unt.edu/housing/item.cfm?type=2925 free mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a34 sony ericsson ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2921 wwe ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=109 nextel ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/funnyringtones_5351.htm funny ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3735 mtv ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=227 order ultracet] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=231 order rivotril] [http://wc1.worldcrossing.com/WebX/.1de60a1f cheap lisinopril] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/xanax_4637.htm xanax online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30359 wwe ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3751 sildenafil online] [http://users.wpi.edu/~dance/blahdocs/uploads/ambien_6489.htm ambien online] [http://students.hsc.unt.edu/housing/item.cfm?type=2847 tramadol online] [http://library.cshl.edu/wp/vb/member.php?u=1345 cheap ultram] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/ativan_9901.htm ativan online] [http://users.wpi.edu/~dance/blahdocs/uploads/lorazepam_3885.htm lorazepam online] [http://users.wpi.edu/~dance/blahdocs/uploads/alprazolam_3561.htm cheap alprazolam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=186 jazz ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30259 alprazolam online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/phentermine_8208.htm cheap phentermine] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=191 cheap lorazepam] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=138 free verizon ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2912 sagem ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/carisoprodol_1193.htm carisoprodol online] [http://students.hsc.unt.edu/housing/item.cfm?type=2911 free cingular ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/realringtones_3783.htm real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=96 levitra online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3749 cheap ultracet] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30349 free cingular ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3737 but phentermine] [http://wc1.worldcrossing.com/WebX/.1de60a0b cheap vigrx] [http://wc1.worldcrossing.com/WebX/.1de60a28 cheap soma] [http://library.cshl.edu/wp/vb/member.php?u=1371 funny ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2868 cheap ambien] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=126 cheap sildenafil] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=129 free sony ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3762 funny ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/paxil_2293.htm buy paxil] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3755 cheap ortho] [http://library.cshl.edu/wp/vb/member.php?u=1360 lorazepam online] [http://users.wpi.edu/~dance/blahdocs/uploads/freeringtones_1986.htm free free ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1348 ativan online] [http://wc1.worldcrossing.com/WebX/.1de60a24 propecia online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30336 free qwest ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/paxil_4058.htm paxil online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3706 buy wellbutrin] [http://library.cshl.edu/wp/vb/member.php?u=1367 cheap didrex] [http://library.cshl.edu/wp/vb/member.php?u=1364 cheap nexium] [http://library.cshl.edu/wp/vb/member.php?u=1342 phentermine online] [http://library.cshl.edu/wp/vb/member.php?u=1376 free motorola ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a25 samsung ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a2d cheap valium] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30277 buy cyclobenzaprine] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30243 cheap ultram] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30327 buy zyban] [http://students.hsc.unt.edu/housing/item.cfm?type=2916 alltel ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1339 cheap tramadol] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=212 propecia online] [http://students.hsc.unt.edu/housing/item.cfm?type=2910 polyphonic ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=177 cheap diethylpropion] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=175 cheap diazepam] [http://library.cshl.edu/wp/vb/member.php?u=1380 free verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30296 clomid online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3767 polyphonic ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3763 free nextel ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f7 nextel ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=98 online lisinopril] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=118 buy prozac] [http://wc1.worldcrossing.com/WebX/.1de60a1e cheap flexeril] [http://wc1.worldcrossing.com/WebX/.1de60a35 free verizon ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/nextelringtones_3485.htm nextel ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3695 carisoprodol online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=241 free sony ericsson ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3723 free motorola ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30318 cheap diethylpropion] {{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: