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
?
trim_right_if不起作用,名称在执行后保持不变。有没有办法使用boost :: regex?
Yes, i am trying not to use find_first_of
and substr
, which i know works.
是的,我试图不使用find_first_of和substr,我知道它可行。
1 个解决方案
#1
0
trim_right_if()
is only if it's in the end of the string.
"Steve_Smith___" ==> "Steve_Smite"
trim_right_if()仅在它位于字符串末尾时才有效。 “Steve_Smith___”==>“Steve_Smite”
what you want to do is replace_all(name, L"_", L"")
;
你想要做的是replace_all(name,L“_”,L“”);
#1
0
trim_right_if()
is only if it's in the end of the string.
"Steve_Smith___" ==> "Steve_Smite"
trim_right_if()仅在它位于字符串末尾时才有效。 “Steve_Smith___”==>“Steve_Smite”
what you want to do is replace_all(name, L"_", L"")
;
你想要做的是replace_all(name,L“_”,L“”);