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

    Prev Next
    Macro
    Find the last occurrence of a substring in a string

    Summary

    The findlast macro returns the index position of the last occurrence of a substring within a target string, or -1 if not found. Searches from the end backwards.

    Syntax

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

    Parameters

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

    Behavior

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

    Examples

    Find last occurrence:

    ${findlast;/;/path/to/file.txt}
    # Returns: 8 (position of last /)
    

    Not found:

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

    Extract file extension:

    ${substring;${filename};${findlast;.;${filename}}}
    

    Get last path component:

    ${substring;${path};${findlast;/;${path}}}
    

    Use Cases

    • Finding last delimiter
    • Extracting file extensions
    • Getting last path component
    • String parsing from end
    • Finding last occurrence

    Notes

    • Returns integer index (0-based)
    • Not a regex search
    • Case-sensitive
    • Searches backwards from end
    • See also: ${find} for first occurrence
    • See also: ${lastindexof} for lists

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home