Created
June 8, 2015 21:17
-
-
Save logie17/f7e57014b3caae51a873 to your computer and use it in GitHub Desktop.
Head Scratcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"unicode/utf8" | |
) | |
func main() { | |
str := "\u0928" + "\u093F" | |
fmt.Println(len(str)) | |
fmt.Println(len("नि")) | |
fmt.Println(utf8.RuneCountInString(str)) | |
fmt.Println(utf8.RuneCountInString("नि")) | |
} | |
Output: | |
% ./unicode | |
6 | |
6 | |
2 | |
2 | |
---- | |
#! /usr/bin/env perl | |
use utf8; | |
use v5.20; | |
use strict; | |
use warnings; | |
binmode STDOUT, ":encoding(UTF-8)"; | |
my $out1 = "\x{0928}\x{093F}"; | |
my $out2 = "नि"; | |
my $count1 = () = $out1 =~ m/\X/g; | |
my $count2 = () = $out2 =~ m/\X/g; | |
say length($out1); | |
say length($out2); | |
# Grapheme count | |
say $count1; | |
say $count2; | |
Output: | |
% perl unicode.pl | |
2 | |
2 | |
1 | |
1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment