strfindtag

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

returns a string after a search string



See Also: strfindafter , strrepn , strrepalias

Example Illustration

 missing image of strfindtag(txt,srch,endstr,endnl)

Syntax

nam=strfindtag(txt,srch,[endstr,endnl])

Input Parameter

txt: text
srch: search string
endstr: end tag to
endnl: optional new line

Output Parameter

nam: trimmed name tag

Examples


[~,b]=system('sw_vers')
strfindtag(b,'ProductName:',newline)




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, strfindtag, is designed to extract a substring from a given text based on a search string and optional end conditions. It is part of the SolidGeometry library.

Input Parameters

Output Results

Algorithm Steps

  1. Retrieve the endstr and endnl parameters using the getfuncparams function. If not provided, default values are used.
  2. Use the strfindafter function to find the start and end indices (ss and ee) of the substring within txt that starts after srch and ends before endstr or a new line if endnl is true.
  3. Extract the substring from txt using the indices ss and ee, and trim any leading or trailing whitespace to get nam.
  4. Extract the remaining text after the end of the substring, starting from ee + 1 + numel(endstr) to the end of txt, and trim it to get nxt.

Example Usage

The function can be used to extract a product name from system information:

[~,b]=system('sw_vers')
strfindtag(b,'ProductName:',newline)

This example searches for the string 'ProductName:' in the output of the sw_vers command and extracts the product name, considering a new line as the end condition.

Algorithm explaination created using ChatGPT on 2025-08-18 23:28. (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