1

これまでのところ、私はコンソール アプリケーションしか書いていません。(Visual Studio 2010 で) MFC を使用する最初のアプリケーションは、基本的に、2 つの複数行ボックス (String^ で示される String[] 配列を使用) と、テキスト処理をアクティブにするボタンを備えたフォームです。String^ で [ を検索し、その後ろの ] を探し、それらの間のすべての文字 ([] を含む) を削除する必要があります。「通常の」C++ 文字列では、これは難しくありません。ただし、String^ はオブジェクトに似ており、MSDN では Remove メソッドを使用するように指示されています。ということで、実装してみました。

public ref class Form1 : public System::Windows::Forms::Form
{
public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }
    String^ DestroyCoords(String^ phrase)
    {
        int CoordsStart = 0;
        int CoordsEnd = 0;
        int CharCount = 0;
        for each (Char ch in phrase)
        {
            if (ch == '[')
                CoordsStart = CharCount;
            if (ch == ']')
            {
                CoordsEnd = CharCount;
                //CoordsEnd = phrase->IndexOf(ch);
                phrase->Remove( CoordsStart , CoordsEnd-CoordsStart );
            }
            CharCount++;
        }
    return phrase;
    }

メソッドを使用したボタン:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             TempString = String::Copy(BoxInput->Text);
             DestroyCoords(TempString);
             BoxOutput->Text = TempString;

関数は正しいタイミングで正しい場所に到達するように見えますが、フレーズ->Remove() メソッドはまったく何もしていません..新人のミス。私は何を間違っていますか?

4

2 に答える 2