LEN Function
Purpose
Returns the number of characters in a text string, including all spaces (leading, trailing, and internal) and punctuation.
Syntax
EXCEL
=LEN(text)
Arguments Breakdown
| Argument | Required? | Description |
|---|---|---|
text |
Required | The text whose length you want to find. Spaces count as characters. |
Practical Examples
1. Character Length Drill
From Formulas_&_Functions_Part_1.xlsx:
If A1 contains "Mostafa " (7 letters + 1 trailing space):
EXCEL
=LEN(A1)
Result: 8.
Whereas after trimming:
EXCEL
=LEN(TRIM(A1))
Result: 7.
2. Detecting Dirty Leading/Trailing Spaces
EXCEL
=IF(LEN(A2) <> LEN(TRIM(A2)), "Dirty Spaces Detected", "Clean")
3. Data Validation Check
Enforcing national ID or phone number digit length:
EXCEL
=LEN(Customer[Phone]) = 11
Related Knowledge
- Notes: 05 Text Manipulation Functions
- Workbook:
11_Demos_and_Workbooks/03_Formulas_and_Functions/Formulas_&_Functions_Part_1.xlsx(Sheet:Text)