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