how to check if a string includes a substring?
emerson_bottero
Member, Developers Posts: 37 ✭✭
Comments
-
match(str, ".*foo.*").hasMatch
Example document:
https://cad.onshape.com/documents/53aba7bd9e61346e9d7b3ac1/w/4de3ec3d738fee155fc49bcf/e/c0bae2abbb6d1f6f4e079a18
2 -
Except you may want to match the substring quoted if it may have special characters:
function containsString(s is string, substring is string) { if (substring == "") return true; const quoted = replace(substring, "[-[\\]{}()*+?.,\\\\^$|#\\s]", "\\$&"); return match(s, ".*" ~ quoted ~ ".*").hasMatch; }
Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc3


