我有一个 System::String
(在 C++ CLI windows 窗体应用程序中),我想对其进行格式化以删除除数字和小数点以外的所有内容。
字符串应该看起来像 "letters0.231 letters $#symbols"
我只想保留 0.231
我不想将这个 String
编码为 std::string
并使用 erase()
函数,然后必须转换回 System::String
有没有办法直接在 System::String
上执行此操作?
最佳答案
我认为您可以使用正则表达式。作为
String ^s = "letters0.231 letters $#symbols";
Regex ^regex = gcnew Regex( "\\d*\\.\\d*" );
s = regex->Match( s )->Value;
double d = Double::Parse( regex->Match( s )->Value );
Console::WriteLine( "s = {0}", s );
Console::WriteLine( "d = {0}", d );
关于c++ - 从 System::String 中删除除数字和小数点以外的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20103689/