String Character Length: Difference between revisions

Content deleted Content added
verified that AWK example only does byte length
→‎{{header|C}}: remove incorrect examples
Line 27:
 
=={{header|C}}==
'''Compiler:''' GCC 3.3.3???
'''Standard:''' [[ANSI C]] (AKA [[C89]]):
 
For wide character strings (usually Unicode uniform-width encodings such as UCS-2 or UCS-4):
'''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>
Line 82 ⟶ 45:
return 0;
}
 
''TODO: non-standard library calls for system multi-byte encodings, such as _mbcslen()''
 
=={{header|Objective-C}}==