Quantcast
Viewing all articles
Browse latest Browse all 189

How remove specified substring and everything after it to the end of a string?

If I have, say, the string,

txt = "now is the time for all (good) men"

then I want to remove the substring beginning with "for" and ending at the end of the string, namely, remove:

subtext = "for all (good) men"

I do realize that an expression of the form StringReplace[txt, regex ->""] or StringReplace[txt, pattern->""]will do it, but I don't know what regular expression or pattern to use.

The part of the substring to be omitted definitely begins with the specific text "for", but anything could follow it.


Viewing all articles
Browse latest Browse all 189

Trending Articles



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