0

我正在努力在托管字符串上调用 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()方法?

4

1 回答 1

3

就像在 C++ 中所做的一样,使用指针表示法:

filename = filename->Trim();
于 2013-02-12T14:54:28.717 回答