Re: [ROOT] How to extract from string

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Tue Jul 23 2002 - 14:20:29 MEST


Hi Shawn,

  with TString this is easily done using the operator()(start, len):

TString s("bla blu bla")
TString sub = s(4,3);

Cheers, Fons.



On Tue, 2002-07-23 at 13:57, Shawn Kwang wrote:
> Brett; Simon,
> 
> I originally wrote a C++ program to do what I want.  Now I am trying to do it 
> in ROOT.  I thought that most of C++ was compatible with ROOT, but 
> string::substr seems to be an exception.
> 
> Here are some lines from my ROOT macro.
> 
>     const int commentstart=67;
>     const int commentlength=180;
>     string inputstring;
>     string comments;
> 
> (stuff)
>     inputstring=/*(line from a file)*/
>     //Takes the comments section as a substring
>     comments=inputstring.substr(commentstart, commentlength);
> 
> When I run this ROOT actually dies.  It does not spit an error.  It does not 
> give back a ROOT prompt.  All I get back is my tsch prompt.
> 
> Sincerely,
> Shawn Kwang
> 
> On Monday 22 July 2002 20:30, Brett Viren wrote:
> > STL's string has
> >
> > 	string string::substr(begin_index, end_index).
> >
> > The indices count from 0.
> >
> > -Brett.
> >
> > Simon Dean writes:
> >  > Hi Shawn,
> >  >
> >  > You could try doing
> >  >
> >  > char mystring[200] = <the_name_of_your_TString_here>->Data();
> >  >
> >  > and then you could access whichever part of the string you wanted by
> >  > using the index; mystring[67] or whatever. Obviously, 'mystring' needs
> >  > to be big enough to accomodate your TString.
> >  >
> >  > Hope that helps,
> >  >
> >  > cheers,
> >  >
> >  > Simon
> >  >
> >  > On Mon, 22 Jul 2002, Shawn Kwang wrote:
> >  > > Roottalk,
> >  > >
> >  > >     I want to extract a portion of a string (TString class).  All I
> >  > > know is that the first character of the portion to be extracted starts
> >  > > at position 67.  The portion is not constant so I can't use
> >  > > TString::Substring (since it looks for a pattern).
> >  > >
> >  > >     I thought there might be a ROOT function that does what I want,
> >  > > TString:Strip but I am not sure.
> >  > >
> >  > > TIA,
> >  > > Shawn Kwang
-- 
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 7679480



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:00 MET