strlen()
Learn how to use the strlen() function to measure the length of the input string.
Returns the length, in characters, of the input string.
Syntax
strlen(source)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| source | string | ✔️ | The string for which to return the length. |
Returns
Returns the length, in characters, of the input string.
Examples
String of letters
print length = strlen("hello")
Output
| length |
|---|
| 5 |
String of letters and symbols
print length = strlen("⒦⒰⒮⒯⒪")
Output
| length |
|---|
| 5 |
String with grapheme
print strlen('Çedilla') // the first character is a grapheme cluster
// that requires 2 code points to represent
Output
| length |
|---|
| 8 |
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.