Jump to content

String Character Length: Difference between revisions

m
no edit summary
mNo edit summary
Line 59:
char *p = (char *) string;
while (*p++ != '\0') length++ ;
return 0;
Line 93:
}
 
==[[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>
Line 124:
 
'''Platform:''' [[.NET]]
'''Language Version:''' 1.0+
 
string s = "Hello, world!";
Line 172:
 
binary
: utf8+ ( str -- str )
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+ 1D12A
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+ 1D12A represented by a UTF-16 surrogate pair
var len2 = str2.length; //2
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.