Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
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


