Skip to content

[Edit] Lua: string.len() #6943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions content/lua/concepts/strings/terms/len/len.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
Title: '.len()'
Description: 'Returns the total number of characters present in a specified string.'
Description: 'Returns the total number of bytes present in a specified string.'
Subjects:
- 'Code Foundations'
- 'Computer Science'
Expand All @@ -14,7 +14,7 @@ CatalogContent:
- 'paths/computer-science'
---

The **`.len()`** method returns the total number of characters present in a specified string.
The **`.len()`** method returns the number of bytes in a string. It is identical to the `#` operator.

## Syntax

Expand All @@ -24,20 +24,20 @@ string.len(s)

- `s`: The input string whose length is to be determined.

> Note: Calling `string.len()` without any arguments will result in an error.
> **Note:** Calling `.len()` without any arguments will result in an error.

## Example

The following example demonstrates the usage of the `.len()` method:

```lua
town = "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch"
lenExample = string.len(town)
print(lenExample)
hello = "hello"
hello_len = string.len(hello)
print(hello_len)
```

The above code produces the following output:

```shell
58
5
```