TString problem (SOLVED)

Hello,

I have been trying to extract a substring from a string. Below is a sample program.

#include <TString.h>
#include <Rtypes.h>
#include

using namespace std;

int main(int argc, char **argv)
{

TString s(“OutFormat=0.0074;3334444cccc”);
// find ‘=’ and ';" and extract string in between

Ssiz_t i1 = s.First(’=’) + 1;
Ssiz_t i2 = s.First(’;’) - 1;
TString s1 = s(i1, i2);
cout << " " << s << " i1 " << i1 << " i2 " << i2 << " s1 " << s1 << endl;

s = “OutFormat=0.0074;”;
i1 = s.First(’=’);
i2 = s.First(’;’);
s1 = s(i1 + 1, i2 - 1);
cout << " " << s << " i1 " << i1 << " i2 " << i2 << " s1 " << s1 << endl;
return 0;
}

and the output is
OutFormat=0.0074;3334444cccc i1 10 i2 15 s1 0.0074;3334444c
OutFormat=0.0074; i1 9 i2 16 s1 0.0074;

root Version 5.09/01 16 December 2005 on FC4 with gcc 4.0.2

I would like to extract a number from in between ‘=’ and ‘;’.

I appreciate any tips.

Michal

The proper code is

#include <TString.h>
#include <Rtypes.h>
#include

using namespace std;

int main(int argc, char **argv)
{

TString s(“OutFormat=0.0074;3334444cccc”);
// find ‘=’ and ';" and extract string in between

Ssiz_t i1 = s.First(’=’) + 1;
Ssiz_t i2 = s.First(’;’);
Int_t ls = i2 - i1;
TString s1 = s(i1, ls);
cout << " " << s << " i1 " << i1 << " i2 " << i2 << " s1 " << s1 << endl;

s = “OutFormat=0.0074;”;
i1 = s.First(’=’) + 1;
i2 = s.First(’;’);
ls = i2 - i1;
s1 = s(i1, ls);
cout << " " << s << " i1 " << i1 << " i2 " << i2 << " s1 " << s1 << endl;
return 0;

}
and the output

OutFormat=0.0074;3334444cccc i1 10 i2 16 s1 0.0074
OutFormat=0.0074; i1 10 i2 16 s1 0.0074

I assume that this problem is resolved.

Philippe

Yes

Michal