Re: TString index operator

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Tue Oct 19 1999 - 16:33:39 MEST


Hi Volker,

   TSubString is mostly for internal consumption used by TString. What
you see is correct behaviour for the TSubString, but you should use
it differently, examples:

Do this to get expected behaviour:

TString a = "this is only a test"
TString b = a(5,2)
b.Data()
(char* 0x85e65a4)"is"

Now with a substring:

TSubString c = a(5,2)
c.Data()
(char* 0x86096f9)"is only a test"
c.Length()
(Ssiz_t)2

As you can see the substring stores a pointer to the begin of the
substring and the length. It does not modify or copy the original.

So, just use only TStrings like shown above. The same for the TRegexp
case.

Cheers, Fons.





Volker Hejny wrote:
> 
> Hi,
> 
> as I understood there is a operator() in TString defined as
> 
>         TSubString operator()(Ssiz_t start, Ssiz_t len)
> 
> So I tried the following:
> 
> > TString test("This is only a test!");
> > TSubString stest = test(5,2);
> 
> I expected stest.Data() to be "is", but
> 
> > stest.Data()
> (char* 0x8593f49)"is only a test!");
> 
> is something I don't understand.
> 
> I also tried to use
> 
>         TSubString operator()(const TRegexp& re)
> 
> in the same way and the result was much the same.
> 
> Is this the right behaviour of these functions?
> 
> Best regards,
> Volker
> 
> --
> Volker Hejny                    Tel: 02461/616853                      **
> Institut f. Kernphysik          Fax: 02461/613930                     **
> ---------------------------------------------------------------- **  ** ---
> Forschungszentrum Juelich GmbH, D-52425 Juelich                    **

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:41 MET