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
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
- txt: The text in which to search.
- srch: The string to find within the text.
- endstr: The end string that marks the end of the search segment.
- endnl: A boolean indicating if a new line should also be considered as an end string.
Output Results
- ff: Index of starting positions of the found segments.
- ee: Index of end positions of the found segments.
- gg: Index of starting positions adjusted for the length of the search string.
- hh: Index of end positions adjusted for the length of the end string.
- str: The substring found between the start and end positions.
Algorithm Steps
- Convert
txt to a character array to ensure compatibility with future MATLAB versions.
- Retrieve optional parameters
endstr and endnl using getfuncparams.
- Determine the number of characters in
srch and endstr.
- 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.
- If
srch is empty, set the starting index to 1.
- Find all occurrences of
endstr in txt and adjust the indices to point to the character before the end string.
- If
endnl is true, also consider new line characters as end strings and sort the indices.
- Initialize an array
dd to store the end indices for each found start index.
- 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.
- Assign the calculated end indices to
ee.
- Calculate
gg and hh by adjusting ff and ee for the lengths of srch and endstr, respectively.
- Extract the substring between the first start and end indices and assign it to
str.
- 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