• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • Introduction
      • How to install bnd
      • Guided Tour Workspace & Projects
      • bnd / bndlib Features and JAR Wrapping Techniques
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Concepts
      • Background
      • Best practices
    • Build and Development
      • Build
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • bnd CLI Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • length STRING

    Prev Next
    Macro
    Get the length of a string in characters

    Summary

    The length macro returns the number of characters in a string. Returns 0 if no argument is provided.

    Syntax

    ${length[;<string>]}
    

    Parameters

    • string (optional) - The string to measure. If omitted, returns 0.

    Behavior

    • Returns the character count
    • Returns 0 if no string provided
    • Counts all characters including spaces
    • Unicode characters count as single characters

    Examples

    Get string length:

    ${length;hello world}
    # Returns: 11
    

    Check if empty:

    ${if;${length;${value}};has-value;empty}
    

    Validate input length:

    ${if;${length;${password}};password-ok;password-required}
    

    No argument:

    ${length}
    # Returns: 0
    

    Use Cases

    • String length validation
    • Checking for empty strings
    • Input validation
    • String size limits
    • Conditional logic based on length

    Notes

    • Returns integer count
    • Includes all characters (spaces, newlines, etc.)
    • Unicode safe
    • See also: ${size} for list element count

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home