-3

c# regexを使用して、すべての「rect NAME = null」を見つけるのに役立ちます。(グローバルとエンドグローバルの間)

    //Text example:
...
         globals
            ...
        boolexpr cj_true_bool_4896bnao87
        string udg_globals = "endglobals"
        trigger gg_trg___________________________u=null
        rect gg_rct_MyReg1=null
        rect     ra2462346  =            null
            ...
          endglobals
...

私のコード(、作業中):

  1. private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { string startglobs = @"^\s*globals\s*$"; string endglobs = @"^\s*endglobals\s*$"; string currrect = @"^\s*rect\s+(. )\s =\s*null\s*";

                    using (StreamReader file = new StreamReader(openFileDialog1.FileName))
                    {
                        string currline;
                        bool globalstate = false;
                        while ((currline = file.ReadLine()) != null)
                        {
                            /* find globals */
                            Regex startr = new Regex(startglobs);
                            Match startm = startr.Match(currline);
                            if (startm.Success)
                                globalstate = true;
    
    
                            /* find endglobls */
                            Regex endr = new Regex(endglobs);
                            Match endm = endr.Match(currline);
                            if (endm.Success)
                                globalstate = false;
    
                            /* if opened globals find global rect */
                            if (globalstate)
                            {
                                Regex foundrectr = new Regex(currrect);
                                Match foundrectm = foundrectr.Match(currline);
                                if (foundrectm.Success)
                                {
                                    MessageBox.Show(foundrectm.Groups[1].ToString());
                                }
                            }
                        }
    
                    }
    
                }
    
4

1 に答える 1

1

ヒントをあげる...

必要な正規表現は

rect (.*)\s?=\s?null

regex クラスを使用してそれを実行する方法を学習する必要があります。MatchCollections と Groups が興味深いものになるかもしれません。

これで、問題を 10 分で解決するのに十分な情報が得られましたが、自分で読む必要があります...

于 2013-06-17T12:06:48.993 に答える