1

I need to truncate a string after an underscore. Example:-

std::wstring name = L"Steve_Smith";
trim_right_if(name, is_any_of(L"_"));

The trim_right_if is not working, the name remains the same after its execution. Is there a way using boost::regex ?

Yes, i am trying not to use find_first_of and substr, which i know works.

Coding Mash
  • 3,338
  • 5
  • 24
  • 45

1 Answers1

0

trim_right_if() is only if it's in the end of the string.
"Steve_Smith___" ==> "Steve_Smite"

what you want to do is replace_all(name, L"_", L"");

Roee Gavirel
  • 18,955
  • 12
  • 67
  • 94
  • replace_all only removes the underscore, the output is SteveSmith.I am actually trying to rename a file which has an underscore, for example test_doc.txt ==> test – user1690041 Oct 10 '12 at 16:49
  • @user1690041 - Ha, I didn't understand the question correctly... but it's good you found the answer. – Roee Gavirel Oct 11 '12 at 07:04