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

Calculate the display width of a string in Java

If you just want to use AWT, then use Graphics.getFontMetrics (optionally specifying the font, for a non-default one) to get a FontMetrics and then FontMetrics.stringWidth to find the width for the specified string. For example, if you have a Graphics variable called g, you’d use: int width = g.getFontMetrics().stringWidth(text); For other toolkits, you’ll need to … Read more

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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)