Difference between revisions of "Number of characters"

From LemonWiki共筆
Jump to: navigation, search
m
(+ SQLite)
Line 61: Line 61:
 
</PRE>
 
</PRE>
 
* [https://dev.mysql.com/doc/refman/8.0/en/char.html MySQL :: MySQL 8.0 Reference Manual :: 11.4.1 The CHAR and VARCHAR Types] e.g. {{kbd | key=<nowiki>VARCHAR(5)</nowiki>}} or {{kbd | key=<nowiki>CHAR(5)</nowiki>}} means can hold up to 5 characters.
 
* [https://dev.mysql.com/doc/refman/8.0/en/char.html MySQL :: MySQL 8.0 Reference Manual :: 11.4.1 The CHAR and VARCHAR Types] e.g. {{kbd | key=<nowiki>VARCHAR(5)</nowiki>}} or {{kbd | key=<nowiki>CHAR(5)</nowiki>}} means can hold up to 5 characters.
 +
 +
 +
== SQLite ==
 +
[https://www.sqlitetutorial.net/sqlite-functions/sqlite-length/#targetText=SQLite%20Length,returns%20the%20number%20of%20bytes. Length] function
 +
<PRE>
 +
SELECT LENGTH("狐"); /* return 1 */
 +
SELECT LENGTH("《王大文 Dawen》"); /* return 11 */
 +
</PRE>
  
 
== Excel ==
 
== Excel ==

Revision as of 18:08, 28 October 2019

String example Number of characters Number of bytes
fox 3 3
The quick brown fox jumps over the lazy dog 43 43
1 3
1 3
🐘 1 4
敏捷的棕毛狐狸從懶狗身上躍過 14 28

PHP

// number of characters
echo mb_strlen("狐", 'UTF-8') . PHP_EOL; // return 1
echo mb_strlen("《王大文 Dawen》", 'UTF-8') . PHP_EOL; // return 11

// string length (number of bytes)
echo strlen("狐") . PHP_EOL; // return 3
echo strlen("《王大文 Dawen》") . PHP_EOL; // return 21

MySQL

// number of characters
SELECT CHAR_LENGTH("狐"); /* return 1 */
SELECT CHAR_LENGTH("《王大文 Dawen》"); /* return 11 */

// number of bytes
SELECT LENGTH("狐"); /* return 3 */
SELECT LENGTH("《王大文 Dawen》"); /* return 21 */


SQLite

Length function

SELECT LENGTH("狐"); /* return 1 */
SELECT LENGTH("《王大文 Dawen》"); /* return 11 */

Excel

// number of characters
=LEN("狐") // return 1
=LEN("《王大文 Dawen》") // return 11

// number of bytes
=LENB("狐") // return 2
=LENB("《王大文 Dawen》") // return 16