How to get the number of characters in a string

You can try RuneCountInString from the utf8 package. returns the number of runes in p that, as illustrated in this script: the length of “World” might be 6 (when written in Chinese: “世界”), but the rune count of “世界” is 2: package main import “fmt” import “unicode/utf8” func main() { fmt.Println(“Hello, 世界”, len(“世界”), utf8.RuneCountInString(“世界”)) } … Read more

Measure string size in Bytes in php

You can use mb_strlen() to get the byte length using a encoding that only have byte-characters, without worring about multibyte or singlebyte strings. For example, as drake127 saids in a comment of mb_strlen, you can use ‘8bit’ encoding: <?php $string = ‘Cién cañones por banda’; echo mb_strlen($string, ‘8bit’); ?> You can have problems using strlen … Read more

What is the string length of a GUID?

It depends on how you format the Guid: Guid.NewGuid().ToString() = 36 characters (Hyphenated) outputs: 12345678-1234-1234-1234-123456789abc Guid.NewGuid().ToString(“D”) = 36 characters (Hyphenated, same as ToString()) outputs: 12345678-1234-1234-1234-123456789abc Guid.NewGuid().ToString(“N”) = 32 characters (Digits only) outputs: 12345678123412341234123456789abc Guid.NewGuid().ToString(“B”) = 38 characters (Braces) outputs: {12345678-1234-1234-1234-123456789abc} Guid.NewGuid().ToString(“P”) = 38 characters (Parentheses) outputs: (12345678-1234-1234-1234-123456789abc) Guid.NewGuid().ToString(“X”) = 68 characters (Hexadecimal) outputs: {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x9a,0xbc}}

How to get the number of characters in a std::string?

If you’re using a std::string, call length(): std::string str = “hello”; std::cout << str << “:” << str.length(); // Outputs “hello:5” If you’re using a c-string, call strlen(). const char *str = “hello”; std::cout << str << “:” << strlen(str); // Outputs “hello:5” Or, if you happen to like using Pascal-style strings (or f***** strings … Read more