Logo

Programming-Idioms

History of Idiom 169 > diff from v110 to v111

Edit summary for version 111 by programming-idioms.org:
[Clojure] Added Demo URL

Version 110

2022-07-13, 14:16:41

Version 111

2022-08-18, 22:39:31

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.

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.

Variables
n,s
Variables
n,s
Extra Keywords
size characters chars number runes
Extra Keywords
size characters chars number runes
Code
(def n (.codePointCount s 0 (count s)))
Code
(def n (.codePointCount s 0 (count s)))
Comments bubble
This properly handles Unicode characters. Using count alone will not work for Unicode characters encoded in more than one byte.
Comments bubble
This properly handles Unicode characters. Using count alone will not work for Unicode characters encoded in more than one byte.
Demo URL
https://replit.com/@ProgIdioms/UnsteadyHotPublishers#main.clj