希望和广大热爱技术的童鞋一起交流,成长。
分类: Windows平台
2015-04-15 16:36:04
CString str = "\n\t a";
str.TrimLeft();
str为“a”;
如果没有参数,从左删除字符(\n\t空格等),至到遇到一个非此类字符.
当然你也可以指定删除那些字符.
如果指定的参数是字符串,那么遇上其中的一个字符就删除.
CString str = "abbcadbabcadb ";
str.TrimLeft("ab");
结果"cadbabcadb "
MSDN
CString strBefore;CString strAfter; strBefore = "Hockey is Best!!!!"; strAfter = strBefore; str.TrimRight('!'); printf("Before: \"%s\"\n", (LPCTSTR) strBefore); printf("After : \"%s\"\n\n", (LPCTSTR) strAfter); strBefore = "Hockey is Best?!?!?!?!"; strAfter = strBefore; str.TrimRight("?!"); printf("Before: \"%s\"\n", (LPCTSTR) strBefore); printf("After : \"%s\"\n\n", (LPCTSTR) strAfter);In the first example above, the string reading, "Hockey is Best!!!!" becomes "Hockey is Best".
In the second example above, the string reading, , "Hockey is Best?!?!?!?!" becomes "Hockey is Best".