Skip to main content

Get Length

Returns the length of a string in bytes (number of characters).

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • String - The string to measure.

Options

This node does not have configurable options.

Output

  • Length - The number of bytes in the string (integer).

How It Works

The Get Length node counts the number of bytes in a string:

  • Returns integer - the byte count
  • Empty string returns 0
  • Spaces count as characters
  • Multi-byte characters (Unicode) may count as multiple bytes
  • ASCII characters are 1 byte each
note

This measures byte length. Some Unicode characters use multiple bytes, so byte length may be different from visual character count.

Usage Examples

Example 1: Simple String

  • String: "Hello"
  • Length: 5

Example 2: Empty String

  • String: ""
  • Length: 0

Example 3: String with Spaces

  • String: "Hello World"
  • Length: 11 (space counts as 1 character)

Example 4: Numbers

  • String: "12345"
  • Length: 5

Example 5: Special Characters

  • String: "Hello!@#"
  • Length: 8

Tips

  • Use for validation (minimum/maximum length checks)
  • Great for limiting input (username, password length)
  • Use for progress indicators (characters typed)
  • Perfect for truncation logic (if too long, truncate)
  • Combine with If node for conditional logic based on length
  • Empty string has length 0

Common Errors and Solutions

Error: Length seems wrong for Unicode characters

  • Cause: Multi-byte Unicode characters count as multiple bytes
  • Solution: This is expected behavior - measures bytes, not visual characters

Error: Need to check if string is empty

  • Solution: Check if length == 0

Practical RPA Examples

Example: Validate Username Length

String: ${msg.username}
GetLength: 8
Validation: If length >= 6 AND length <= 20, valid
Use: Ensure username meets requirements

Example: Validate Password Strength

String: ${msg.password}
GetLength: 12
Validation: If length >= 8, meets minimum requirement
Use: Password strength validation

Example: Check if Empty

String: ${msg.userInput}
GetLength: 0
Check: If length == 0, field is empty
Action: Show "Required field" error

Example: Truncate Long Text

String: ${msg.description}
GetLength: 250
Check: If length > 200, truncate
Action: Show first 200 characters + "..."

Example: Character Counter

String: ${msg.textInput}
GetLength: 45
Display: "45/100 characters"
Use: Real-time character count display

Example: Validate Phone Number

String: ${msg.phoneNumber}
GetLength: 10
Validation: If length == 10, correct format
Use: US phone number validation

Pattern: Input Validation

Validate input length:

Step 1: GetLength on input
Step 2: Check if length meets requirements
Step 3: If invalid, return error
Step 4: If valid, continue processing

Pattern: Conditional Truncation

Truncate if too long:

Step 1: GetLength on text
Step 2: If length > maxLength
Step 3: Extract first maxLength characters
Step 4: Append "..."

Pattern: Empty Check

Check if string has content:

Step 1: GetLength
Step 2: If length == 0, empty
Step 3: If length > 0, has content

Use Cases

Form Validation

Username: 6-20 characters
Password: 8+ characters
Description: 0-500 characters

Data Quality Checks

If length == 0: Missing data
If length > expected: Data corruption
If length < minimum: Incomplete data

Content Management

Title: Max 100 characters
Summary: Max 200 characters
Content: Max 5000 characters

API Validation

Check payload size before sending
Ensure fields meet API requirements
Validate response data

Validation Patterns

Minimum Length

GetLength > minLength
Example: Password must be at least 8 characters

Maximum Length

GetLength <= maxLength
Example: Username must be at most 20 characters

Exact Length

GetLength == exactLength
Example: ZIP code must be exactly 5 characters

Range

GetLength >= min AND GetLength <= max
Example: Description between 10 and 500 characters

Combining with Other Nodes

With If Node

GetLength → If length > 100 → Truncate

With Trim First

Trim (remove spaces) → GetLength → Validate

With Split

Split → Get array length (number of parts)
  • Trim - Remove whitespace before measuring
  • Split - Get array length for word count
  • Count - Count specific substrings
  • Includes - Check if contains substring