Hi all, I've written the following piece of macro to read in a text file with a number of lines with the first field in each line used (later in the larger macro) to label the .eps and .gif files produced (after producing graphs, ...) and the second field, used as titles of the graphs. Since at a later stage, I do the following inside another loop, i.e. .... char psFile_name[40]; sprintf(psFile_name,"%s_%s.eps",Basename,PsVarName[n]); .... I would need to get rid of the blank spaces before and after the first field in each line. So I do this by using Strip but not without doing some gymnastics between TString and char* (as I've highlighted in the macro). The macro works but I was just wondering whether there is a more graceful way of handling this... i.e. can I not have a Strip method that takes as an argument another TString and the character to be stripped, returning the stripped string? Looking in http://root.cern.ch/cgi-bin/print_hit_bold.pl/root/html/src/TString.cxx.html?TString#first_hit , I wasn't able to find one. Thanks and best wishes, Mina Nozar ////////////////////////////////////////// void Label(const int Ncol, char * LabelFile_name) { // root // .L Label.C // .x Label.C(34,"test.label"); #include <iostream.h> #include <string.h> // Reading in the label file ifstream LabelFile; LabelFile.open(LabelFile_name, ios::in); Int_t nline = 0; TString VarName[Ncol]; TString PsVarName[Ncol]; char line[100]; TString tmp, tmp1; const char* tmp2; while (!LabelFile.eof() && nline<(Ncol/2)) { LabelFile.getline(line,100, '\n'); tmp = line; tmp1 = tmp(0,6); tmp2 = tmp1; PsVarName[2*nline] = Strip(tmp2); VarName[2*nline] = tmp(7,tmp.Length()-6); cout << "PsVarName[" << 2*nline<< "]: " << PsVarName[2*nline] << " VarName[" << 2*nline << "]: " << VarName[2*nline] << endl; nline++; } test.label file looks like: Mass Mass(#pi^{+}#pi^{+}#pi^{-}) GeV Total Total Intensity 0-+_1 0^{-+}0^{+}_0_#sigma 0-+_2 0^{-+}0^{+}_0_f_{0}(980) 0-+_3 0^{-+}0^{+}_1_#rho(770) 1++_1 1^{++}0^{+}_0_#rho(770) 1++_2 1^{++}1^{+}_0_#rho(770) 1++_3 1^{++}1^{-}_0_#rho(770) 1++_4 1^{++}0^{+}_2_#rho(770) 1++_5 1^{++}1^{+}_2_#rho(770) 1++_6 1^{++}1^{-}_2_#rho(770) 1++_7 1^{++}0^{+}_1_#sigma 1++_8 1^{++}1^{+}_1_#sigma 1++_9 1^{++}1^{-}_1_#sigma 1++_10 1^{++}0^{+}_1_f_{0}(980) 1++_11 1^{++}1^{+}_1_f_{0}(980) 1++_12 1^{++}1^{-}_1_f_{0}(980) Running the above peice results in: Openning file: test.label PsVarName[0]: Mass VarName[0]: ass(#pi^{+}#pi^{+}#pi^{-}) GeV PsVarName[2]: Total VarName[2]: Total Intensity PsVarName[4]: 0-+_1 VarName[4]: 0^{-+}0^{+}_0_#sigma PsVarName[6]: 0-+_2 VarName[6]: 0^{-+}0^{+}_0_f_{0}(980) PsVarName[8]: 0-+_3 VarName[8]: 0^{-+}0^{+}_1_#rho(770) PsVarName[10]: 1++_1 VarName[10]: 1^{++}0^{+}_0_#rho(770) PsVarName[12]: 1++_2 VarName[12]: 1^{++}1^{+}_0_#rho(770) PsVarName[14]: 1++_3 VarName[14]: 1^{++}1^{-}_0_#rho(770) PsVarName[16]: 1++_4 VarName[16]: 1^{++}0^{+}_2_#rho(770) PsVarName[18]: 1++_5 VarName[18]: 1^{++}1^{+}_2_#rho(770) PsVarName[20]: 1++_6 VarName[20]: 1^{++}1^{-}_2_#rho(770) PsVarName[22]: 1++_7 VarName[22]: 1^{++}0^{+}_1_#sigma PsVarName[24]: 1++_8 VarName[24]: 1^{++}1^{+}_1_#sigma PsVarName[26]: 1++_9 VarName[26]: 1^{++}1^{-}_1_#sigma PsVarName[28]: 1++_10 VarName[28]: 1^{++}0^{+}_1_f_{0}(980) PsVarName[30]: 1++_11 VarName[30]: 1^{++}1^{+}_1_f_{0}(980) PsVarName[32]: 1++_12 VarName[32]: 1^{++}1^{-}_1_f_{0}(980)
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET