我正在努力在托管字符串上调用Trim()方法来删除任何前导和尾随空格。
我试过了:
System::String^ filename = " export.csv ";
filename = System::String::Trim(filename);
filename = filename::Trim();
filename = filename.Trim();
这给出了我的错误:
error C2665: 'System::String::Trim' : none of the 2 overloads could convert all the argument types
或
error C2825: 'filename': must be a class or namespace when followed by '::'
error C2039: 'Trim' : is not a member of ''global namespace''
error C2146: syntax error : missing ';' before identifier 'Trim'
error C3861: 'Trim': identifier not found
或
error C2228: left of '.Trim' must have class/struct/union
您应该如何在C ++ / CLI中修剪托管字符串?为什么我不能使用System::String::Trim()方法?
答案 0 :(得分:2)
就像在C ++中一样,使用指针表示法:
filename = filename->Trim();