Syntax
[pp,ccc]=wordfind(txt,word,[sep])
Input Parameter
txt : | | charchain to search in |
word : | | word to look for |
sep : | | separators; default is {',',' ',';'} |
Output Parameter
pp : | | array of hits |
ccc : | | separated words |
Examples
wordfind ('Introduced first in SolidGeometry 5.4', 'intro') % Not found
wordfind ('Introduced first in SolidGeometry 5.4', 'in') % 3rd word
wordfind ('Introduced first in SolidGeometry 5.4 in text', 'in') % two words
Copyright 2023-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 algorithm is designed to find specific words within a given string and return their positions and the separated words. It is part of the SolidGeometry library.
Input Parameters
- txt: A character chain (string) in which the search is performed.
- word: The specific word to look for within the string.
- sep: Optional parameter. A set of separators used to split the string into words. The default separators are a comma, space, and semicolon: {',', ' ', ';'}.
Output Results
- pp: An array containing the positions of the found word(s) within the separated words.
- ccc: An array of the separated words from the input string.
Algorithm Steps
- Initialize the default separators as a set containing a comma, space, and semicolon:
sep={',',' ',';'}
.
- Use the function
getfuncparams
to check if a custom separator is provided in varargin
. If provided, update sep
with the custom separators.
- Split the input string
txt
into words using the split
function with the specified separators sep
. Transpose the result to get a column vector of words: ccc=split(txt,sep)'
.
- Find the positions of the specified
word
within the array of separated words ccc
using the ismember
function. Store the positions in the array pp
: pp= find(ismember(ccc,word))
.
Example Usage
wordfind('Introduced first in SolidGeometry 5.4', 'intro')
- The word 'intro' is not found.
wordfind('Introduced first in SolidGeometry 5.4', 'in')
- The word 'in' is found as the 3rd word.
wordfind('Introduced first in SolidGeometry 5.4 in text', 'in')
- The word 'in' is found twice.
Algorithm explaination created using ChatGPT on 2025-08-18 23:35. (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