Skip to content

Instantly share code, notes, and snippets.

@ram1123
Last active August 3, 2021 20:20
Show Gist options
  • Save ram1123/02030e5b55e35885e2a2b7af3c4dd250 to your computer and use it in GitHub Desktop.
Save ram1123/02030e5b55e35885e2a2b7af3c4dd250 to your computer and use it in GitHub Desktop.
Replace a string, check if sub-string is there in a string or not, Tokenize a string based on delimiter (Works within ROOT environment)
void replaceSplit() {
TString string1 = "GluGluToHHTo2G4Q_node_cHHH1_13TeV_HHWWggTag_1_FNUFEBDown01sigma";
TString ToReplace = "HHWWggTag_1";
TString ReplaceWith = "HHWWggTag_FH_1";
std::cout << "==>\t" << string1 << std::endl;
std::cout << "==>\t" << string1.ReplaceAll(ToReplace, ReplaceWith) << std::endl;
std::cout << "==>\t" << string1.Contains("noda") << std::endl;
std::cout << "==>\t" << string1.Contains("Tag_1") << std::endl;
std::cout << "==>\t" << string1.Contains("Tag_FH") << std::endl;
TObjArray* tokens = string1.Tokenize("_");
TIter next(tokens);
TKey *key;
while ( (key = (TKey*)next())) {
std::cout <<"==> " << key->GetName() << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment