Maple für Professional
Maple für Akademiker
Maple für Studenten
Maple Personal Edition
Maple Player
Maple Player für iPad
MapleSim für Professional
MapleSim für Akademiker
Maple T.A. - Testen & beurteilen
Maple T.A. MAA Placement Test Suite
Möbius - Online-Courseware
Machine Design / Industrial Automation
Luft- und Raumfahrt
Fahrzeugtechnik
Robotics
Energiebranche
System Simulation and Analysis
Model development for HIL
Anlagenmodelle für den Regelungsentwurf
Robotics/Motion Control/Mechatronics
Other Application Areas
Mathematikausbildung
Technik
Allgemein- und berufsbildende Schulen
Testen und beurteilen
Studierende
Finanzmodelle
Betriebsforschung
Hochleistungsrechnen
Physik
Live-Webinare
Aufgezeichnete Webinare
Geplante Veranstaltungen
MaplePrimes
Maplesoft-Blog
Maplesoft-Mitgliedschaft
Maple Ambassador Program
MapleCloud
Technische Whitepapers
E-Mail Newsletters
Maple-Bücher
Math Matters
Anwendungs-Center
MapleSim Modell-Galerie
Anwenderberichte
Exploring Engineering Fundamentals
Lehrkonzepte mit Maple
Maplesoft Welcome-Center
Resource-Center für Lehrer
Help-Center für Studierende
StringTools[Search] - search for an occurrence of a string in another string
StringTools[SearchAll] - search for all occurrences of a string in another string
Calling Sequence
Search( pattern, text )
Search( patlist, text )
Search( pattern, textlist )
SearchAll( pattern, text )
SearchAll( patlist, text )
SearchAll( pattern, textlist )
Parameters
pattern
-
string
text
patlist
list of strings
textlist
Description
The Search(pattern, text) function searches for the string pattern in the string text. If pattern does not occur as a substring of text, then is returned. Otherwise, the index of the first character of the first occurrence of pattern in text is returned.
Either the first or second argument of Search, but not both, can be a list of strings.
If the first argument to Search is a list of strings, then Search searches for occurrences of any of the patterns in patlist in the specified string text. It returns a pair consisting of the offset of the first occurrence of any of the patterns found in text, and the index of the pattern that matches.
The cost of preprocessing a single pattern can be amortized by passing a list of strings as the second argument. This is functionally equivalent to computing map2( Search, Pattern, Texts ), where Pattern is the pattern string to search for, and Texts is a list of strings.
The SearchAll(pattern, text) function finds all occurrences of the string pattern in text. It returns an expression sequence of the indices of the first characters of occurrences of pattern in text. This expression sequence is NULL if pattern does not occur in text.
The procedure SearchAll also accepts a list of strings for either its first or its second argument, but not both.
When presented with a list of strings patlist as the first argument, SearchAll searches for all occurrences of the strings in patlist in the string text. The result of such a search is an expression sequence of pairs (lists of length equal to two) of the form , where offset is the offset into the string text where a match occurred, and id is the index into patlist of the matching string.
Note: You can specify a set of strings instead of a list for either patlist or textlist. However, because matches are identified by their position, it is recommended that you use a list, which has static element positions, rather than a set for patlist or textlist.
Passing a list textlist of strings as the second argument to SearchAll is more efficient than, but otherwise equivalent to, computing the expression .
The procedure Search is similar to the built-in procedure SearchText.
Examples
This result indicates that a match was found at position 1, and that it was the second pattern (L[2]) that matched at that position.
The result above indicates that there are matches at offsets 1, 5, 7, and 8 in the text, that the matching string is "ab" (L[2]) in the first three matches, and the match at offset 8 is "bac" (L[1]).
You can identify all substrings of a specified string that are in a dictionary as follows. (Many systems have such a dictionary in a file such as "/usr/share/dict/words". You can use any word list with one word per line. It does not need to be sorted.)
Subwords := proc( dict, s ) local i; use StringTools in seq( dict[ i ], i = map2( op, 2, [ SearchAll( dict, s ) ] ) ) end use end proc:
Multiple searches using a single pattern can be done more efficiently by passing the strings to be searched in a list in a single call to Search or SearchAll.
See Also
SearchText, Sets and Lists, string, StringTools
Download Help Document