Idiom #169 String length
Assign to the integer n the number of characters of the string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.

Assign to the integer n the number of characters of the string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.
(def n (.codePointCount s 0 (count s)))
auto utf8len(std::string_view const& s) -> size_t
{
std::setlocale(LC_ALL, "en_US.utf8");
auto n = size_t{};
auto size = size_t{};
auto mb = std::mbstate_t{};
while(size < s.length())
{
size += mbrlen(s.data() + size, s.length() - size, &mb);
n += 1;
}
return n;
}
N = string:length(S)
int n = s.length();
local utf8={}
function utf8.bytes(str,index)
local byte=string.byte(str,index)
local ret
if byte==nil then ret=0
elseif byte<128 then ret=1
elseif byte<192 then ret=2
elseif byte<224 then ret=3
else ret=4
end
return ret
end
function utf8.len(str)
local count=0
local fini=#str+1
local index=1
while index~=fini do
count=count+1
index=index+utf8.bytes(str,index)
end
return count
end
local n=utf8.len(s)
n := s.length;
n = len(s)
const n = s.length;
const n = [...s].length;
n : Integer := s'Length;
(defn n[s] (.codePointCount s 0 (count s)))
(def n (.codePointCount s 0 (count s)))
IDENTIFICATION DIVISION. PROGRAM-ID. length. PROCEDURE DIVISION. MOVE FUNCTION LENGTH(s) TO n STOP RUN.
auto utf8len(std::string_view const& s) -> size_t { std::setlocale(LC_ALL, "en_US.utf8"); auto n = size_t{}; auto size = size_t{}; auto mb = std::mbstate_t{}; while(size < s.length()) { size += mbrlen(s.data() + size, s.length() - size, &mb); n += 1; } return n; }
int n = s.Length;
size_t n = s.walkLength;
size_t n = s.byGrapheme.walkLength;
size_t n = s.length;
int n = s.length;
n = String.length s
N = string:length(S)
n = len(s)
n := utf8.RuneCountInString(s)
n = length s
int n = s.length();
val n = s.length
(setf n (length s))
(length s)
local n = utf8.len(s)
local utf8={} function utf8.bytes(str,index) local byte=string.byte(str,index) local ret if byte==nil then ret=0 elseif byte<128 then ret=1 elseif byte<192 then ret=2 elseif byte<224 then ret=3 else ret=4 end return ret end function utf8.len(str) local count=0 local fini=#str+1 local index=1 while index~=fini do count=count+1 index=index+utf8.bytes(str,index) end return count end local n=utf8.len(s)
NSUInteger n=s.length;
$n = mb_strlen($s, 'UTF-8');
n := length(s);
n := s.length;
n := Utf8Length(s);
my $n = length( $s );
n = len(s)
n = s.size
n = s.length
let n = s.chars().count();
val n = s.length()
n := s size.
Dim n As Integer = s.Length