【问题标题】:C++ Winform How to parse string array to int array?C ++ Winform如何将字符串数组解析为int数组?
【发布时间】:2015-02-07 04:22:57
【问题描述】:

在主要目标中,我需要通过删除逗号 , 将输入从 ("5,23,12,23...") 更改为 ("5 23 12 ... ")

我已经删除了这个逗号,但是下一个对象是从这个输入数字中找到最小值和最大值。我不知道如何将array<string> 解析为array<int> 来做下一个目标。

我不能这样做number[word]=Convert::ToInt32(words[word]); 所以请有人告诉我如何解决这个问题。

String^ strInput="";
String^ strResult="";
String^ strRemove=",";

array<Char>^Remove=strRemove->ToCharArray();
array<String^>^words;
array<Int32^>^number;
int test;
//get text from input ui
strInput=txtInput->Text;
words=strInput->Split(Remove);

for(int word=0;word<words->Length;word++)
{
    /*number[word]=Convert::ToInt32(words[word]);*/
    test=Int32::Parse(words[word]);
    txtResult->Text+=words[word]+" ";
}

【问题讨论】:

  • 这不是 C++。可能是 C++/CLI。

标签: c++ arrays string winforms int


【解决方案1】:

应该通过添加来解决:

number = gcnew array<Int32^>(words->Length);

在您的 for 循环之前

那么您当前注释的行应该可以工作。

【讨论】:

    猜你喜欢
    • 2012-10-14
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 2017-02-02
    相关资源
    最近更新 更多