Count number of characters: Difference between revisions
Jump to navigation
Jump to search
→Python
(python) |
(→Python) |
||
| Line 130: | Line 130: | ||
</pre> | </pre> | ||
== JavaScript == | |||
Using the [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length length()] function and [https://developer.mozilla.org/en-US/docs/Web/API/Blob Blob] object <ref> [https://stackoverflow.com/questions/2219526/how-many-bytes-in-a-javascript-string How many bytes in a JavaScript string? - Stack Overflow]</ref>. | |||
=== Get the number of characters in a string in JavaScript === | |||
<pre> | |||
var string = "狐" | |||
console.log(string.length); | |||
</pre> | |||
=== Get the number of bytes in a string in JavaScript === | |||
<pre> | |||
var string = "狐" | |||
console.log(new Blob([string]).size); | |||
// returns 3 | |||
</pre> | |||
== References == | == References == | ||