Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #169 String length

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

N = string:length(S)
n : Integer := s'Length;
(def n (.codePointCount s 0 (count s)))
IDENTIFICATION DIVISION.
PROGRAM-ID. length.
PROCEDURE DIVISION.
   MOVE FUNCTION LENGTH(s) TO n
STOP RUN.
int n = s.Length;
import std.uni, std.range;
size_t n = s.byGrapheme.walkLength;
size_t n = s.length;
std.range;
size_t n = s.walkLength;
int n = s.length;
n = String.length s
n = len(s)
import "unicode/utf8"
n := utf8.RuneCountInString(s)
n = length s
const n = s.length;
int n = s.length();
val n = s.length
(length s)
(setf n (length s))
local n = utf8.len(s)
@import Foundation;
NSUInteger n=s.length;
$n = mb_strlen($s, 'UTF-8');
uses LazUtf8;
n := length(s);
uses sysutils;
n := s.length;
uses LazUtf8;
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()
Dim n As Integer = s.Length

New implementation...
programming-idioms.org