String Character Length: Difference between revisions
Content deleted Content added
mNo edit summary |
Undo revision 8082 by Special:Contributions/SdqZt5 (User talk:SdqZt5) |
||
Line 59: | Line 59: | ||
char *p = (char *) string; |
char *p = (char *) string; |
||
while (*p |
while (*p++ != '\0') length++; |
||
return 0; |
return 0; |
||
Line 93: | Line 93: | ||
} |
} |
||
==[[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 |
'''Standard:''' [[ISO C plus plus|ISO C++]] (AKA [[C plus plus 98|C++98]]): |
||
'''Compiler:''' g |
'''Compiler:''' g++ 4.0.2 |
||
#include <string> // note: '''not''' <string.h> |
#include <string> // note: '''not''' <string.h> |
||
Line 124: | Line 124: | ||
'''Platform:''' [[.NET]] |
'''Platform:''' [[.NET]] |
||
'''Language Version:''' 1.0 |
'''Language Version:''' 1.0+ |
||
string s = "Hello, world!"; |
string s = "Hello, world!"; |
||
Line 172: | Line 172: | ||
binary |
binary |
||
: utf8 |
: utf8+ ( str -- str ) |
||
begin |
begin |
||
char |
char+ |
||
dup c@ |
dup c@ |
||
11000000 and |
11000000 and |
||
Line 186: | Line 186: | ||
swap dup c@ |
swap dup c@ |
||
while |
while |
||
utf8 |
utf8+ |
||
swap 1 |
swap 1+ |
||
repeat drop ; |
repeat drop ; |
||
Line 216: | Line 216: | ||
Since Java 1.5, the actual number of characters can be determined by calling the codePointCount method. |
Since Java 1.5, the actual number of characters can be determined by calling the codePointCount method. |
||
String str = "\uD834\uDD2A"; //U |
String str = "\uD834\uDD2A"; //U+1D12A |
||
int length1 = str.length(); //2 |
int length1 = str.length(); //2 |
||
int length2 = str.codePointCount(0, str.length()); //1 |
int length2 = str.codePointCount(0, str.length()); //1 |
||
Line 229: | Line 229: | ||
var len1 = str1.length; //13 |
var len1 = str1.length; //13 |
||
var str2 = "\uD834\uDD2A"; //U |
var str2 = "\uD834\uDD2A"; //U+1D12A represented by a UTF-16 surrogate pair |
||
var len2 = str2.length; //2 |
var len2 = str2.length; //2 |
||