@@ -185,6 +185,52 @@ isEmpty(\"a\"); // returns false
185185</html>" ));
186186 end isEmpty;
187187
188+ function contains "Check if a string contains a substring"
189+
190+ extends Modelica.Icons.Function;
191+
192+ input String string "String to check" ;
193+ input String searchString "Substring to look for" ;
194+ input Boolean caseSensitive= true
195+ "= false, if lower and upper case are ignored for the search" ;
196+ output Boolean result "= true, if searchString can be found anywhere in string" ;
197+
198+ algorithm
199+ if length(searchString) > 0 then
200+ result := find(string, searchString, 1 , caseSensitive) > 0 ;
201+ else
202+ result := true ;
203+ end if ;
204+
205+ annotation (Documentation(info="<html>
206+ <h4>Syntax</h4>
207+ <blockquote><pre>
208+ result = Strings.<strong>contains</strong>(string, searchString);
209+ result = Strings.<strong>contains</strong>(string, searchString, caseSensitive);
210+ </pre></blockquote>
211+
212+ <h4>Description</h4>
213+ <p>
214+ Returns true if \" searchString\" is a substring of \" string\". Otherwise, false is returned.
215+ The optional argument \" caseSensitive\" controls if substrings match, which differ in case only.
216+ </p>
217+ <p>
218+ Empty strings are treated as substring of all strings. Therefore, the result is always true if \" searchString\" is empty.
219+ </p>
220+
221+ <h4>Example</h4>
222+ <blockquote><pre>
223+ import Modelica.Utilities.Strings.contains;
224+
225+ contains(\" foobar\", \" OO\"); // returns false
226+ contains(\" foobar\", \" OO\", false); // returns true
227+ contains(\" foo\", \" bar\"); // returns false
228+ contains(\" \", \" \"); // returns true
229+ contains(\" foo\", \" \"); // returns true
230+ </pre></blockquote>
231+ </html>" ));
232+ end contains;
233+
188234 function count "Count the number of non-overlapping occurrences of a string"
189235 extends Modelica.Icons.Function;
190236 input String string "String that is analyzed" ;
0 commit comments