• 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
  • trim ';' STRING

    Prev Next
    Macro
    Remove leading and trailing whitespace from a string

    Summary

    The trim macro removes leading and trailing whitespace from a string. It uses Java’s String.trim() method, which removes spaces, tabs, newlines, and other whitespace characters.

    Syntax

    ${trim;<string>}
    

    Parameters

    • string - The string to trim

    Behavior

    • Removes leading whitespace characters
    • Removes trailing whitespace characters
    • Returns the trimmed string
    • Preserves whitespace within the string

    Examples

    Remove extra spaces:

    ${trim;  hello world  }
    # Returns: "hello world"
    

    Clean up property value:

    cleaned.value=${trim;${some.property}}
    

    Trim after concatenation:

    ${trim;${first} ${second} }
    

    Process multiline value:

    ${trim;
        some value
    }
    # Returns: "some value"
    

    Use Cases

    • Cleaning up user input
    • Normalizing property values
    • Removing accidental whitespace
    • Processing template output
    • Formatting string values
    • Preparing strings for comparison

    Notes

    • Only removes leading and trailing whitespace
    • Internal whitespace is preserved
    • Whitespace includes spaces, tabs, newlines, etc.
    • Uses Java’s definition of whitespace
    • Empty string after trim remains empty

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home