TString + Strip

Hi,

I currently just can’t figure out how to strip characters from a TString. I know that it’s described in the TString class, however I can’t get it to work - a simple example would be useful. E.g. if I have TString a=“test.eps”, how do I “Strip” the .eps ending?

Cheers,
Carsten

Hi Carsten,

You can do:TString s = "test.eps"; Int_t dot = s.First('.'); Int_t len = s.Length(); s.Remove(dot,len-dot);
For more TString examples see $ROOTSYS/test/tstring.cxx.

Cheers, Ilka

Thanks for the reply. This solution does work, but I was hoping if somebody could explain me how to use the Strip method of TString.

Cheers,
Carsten

Hi Carsten,

This method removes the given character from the beginning and/or from the end of the string. The returned sub-string is printed below the code lines:[code]root [0] TString s = “11test.eps222”;
root [1] s.Strip(TString::kLeading,‘1’)
(class TString)“test.eps222”

root [2] s.Strip(TString::kTrailing,‘2’)
(class TString)“11test.eps”

root [3] s = "333test.eps3333"
root [4] s.Strip(TString::kBoth,‘3’)
(class TString)“test.eps”[/code]
Cheers, Ilka

Hi Carsten,

simply do:

TString a = "test.eps"; a.ReplaceAll(".eps","");
Rene