by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Artificial Intelligence
Introduced first in SolidGeometry 5.4, Creation date: 2023-12-18, Last change: 2025-09-15
See Also:
[pp,ccc]=wordfind(txt,word,[sep])
txt: | charchain to search in | |
word: | word to look for | |
sep: | separators; default is {',',' ',';'} |
pp: | array of hits | |
ccc: | separated words |
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
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.
sep={',',' ',';'}.getfuncparams to check if a custom separator is provided in varargin. If provided, update sep with the custom separators.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)'.word within the array of separated words ccc using the ismember function. Store the positions in the array pp: pp= find(ismember(ccc,word)).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.