• 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
  • find ';' VALUE ';' SEARCHED

    Prev Next
    Macro
    Find the index position of a substring in a string

    Summary

    The find macro returns the starting index position of a substring within a target string, or -1 if not found. This is a simple string search, not a regex pattern match.

    Syntax

    ${find;<target>;<substring>}
    

    Parameters

    • target - The string to search in
    • substring - The substring to find (literal string, not regex)

    Behavior

    • Returns the index of the first occurrence of substring
    • Returns -1 if substring is not found
    • Index is 0-based (first character is position 0)
    • Case-sensitive search
    • Not a regex pattern match

    Examples

    Find substring position:

    ${find;hello world;world}
    # Returns: 6
    

    Search not found:

    ${find;hello world;foo}
    # Returns: -1
    

    Check if string contains substring:

    ${if;${matches;${find;${path};/test/};-?[0-9]+};contains-test;no-test}
    

    Find file extension:

    ${find;${filename};.}
    

    Use Cases

    • Locating substring positions
    • Checking if string contains text
    • String parsing and analysis
    • Finding delimiters
    • Conditional logic based on presence

    Notes

    • Returns integer index (0-based)
    • Not a regex search (use ${matches} for regex)
    • Case-sensitive
    • Returns first occurrence only
    • See also: ${lastindexof} for last occurrence
    • See also: ${matches} for regex matching
    • See also: ${indexof} for list searching

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home