[CMake] Strip a prefix from a string

David.Karr at L-3COM.COM David.Karr at L-3COM.COM
Sun Jan 11 16:38:48 EST 2009


I'm afraid this accidentally went through once already while I was in
the midst of editing it; this time it's for real.

> Suppose I have a string called "foobar". I want to be able to strip a
> specific prefix from that string and have the suffix returned to me.
> So if I wanted to strip "foo", I would get "bar" back. What's the
> easiest way of doing this in CMake?

I would try something like this:

STRING(REGEX REPLACE "^foo" "" VAR_WITHOUT_FOO ${VAR_WITH_FOO})

Then if ${VAR_WITH_FOO} is "foobar", this will set
${VAR_WITHOUT_FOO} to "bar".

(I've been using a similar device, except that in my case I'm
stripping stuff from the end of the string.)

-- David




More information about the CMake mailing list