strfindafter

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Text/Strs/Chars/Links
Introduced first in SolidGeometry 5.0, Creation date: 2021-01-31, Last change: 2025-09-15

finds text between start tokens and endtokens

Description

powerful parsing function

See Also: strfindafter , strfindtag , strrepn , strrepalias

Example Illustration

 missing image of strfindafter(text,srch,endstr,endnl)

Syntax

[ff,ee]=strfindafter(text,srch,[endstr,endnl])

Input Parameter

text: text to search
srch: str to find
endstr: endstring
endnl: if true new line is also accepted as endstr

Output Parameter

ff: index of starting positions
ee: index of end positions




Copyright 2021-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, strfindafter, is a powerful parsing function designed to find text between specified start and end tokens within a given string. It is part of the SolidGeometry library and was introduced in version 5.0.

Input Parameters

Output Results

Algorithm Steps

  1. Convert txt to a character array to ensure compatibility with future MATLAB versions.
  2. Retrieve optional parameters endstr and endnl using getfuncparams.
  3. Determine the number of characters in srch and endstr.
  4. If srch is not empty, find all occurrences of srch in txt and adjust the indices to point to the end of the found string.
  5. If srch is empty, set the starting index to 1.
  6. Find all occurrences of endstr in txt and adjust the indices to point to the character before the end string.
  7. If endnl is true, also consider new line characters as end strings and sort the indices.
  8. Initialize an array dd to store the end indices for each found start index.
  9. For each start index in ff, find the first end index that is greater than or equal to the start index. If no such end index exists, set it to the length of txt.
  10. Assign the calculated end indices to ee.
  11. Calculate gg and hh by adjusting ff and ee for the lengths of srch and endstr, respectively.
  12. Extract the substring between the first start and end indices and assign it to str.
  13. If no output arguments are specified, print each found substring using dbprintf.
Algorithm explaination created using ChatGPT on 2025-08-19 07:43. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21