Quantcast
Viewing all articles
Browse latest Browse all 186

Remove words from a string that contain special characters

I have a string like this:

string="there is a humble-bee in Hanna's garden";

Now I want to exclude those words that contain "-" and "'". My own solution would be:

StringDelete[string,Cases[StringSplit[string," "], _?(StringContainsQ[#, {"'", "-"}] &)]]

so the outcome is:

"there is a in garden"

But I was wondering whether there is a more elegant solution?


Viewing all articles
Browse latest Browse all 186

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>