C # loops through file streams, reads by rows

Source: Internet
Author: User

 Publicdictionary<string,string>getsourcediskselements (String section) { section="["+Section ; Dictionary<string,string> Keytovalue =Newdictionary<string,string>(); //Open the file stream and start reading the file        using(StreamReader sin =NewStreamReader (NewFileStream (Path, FileMode.Open, FileAccess.Read, FileShare.Read))) {                 for(String str = sin.) ReadLine (); str! =NULL; str =sin. ReadLine ()) {if(str. Trim (). StartsWith (section, stringcomparison.ordinalignorecase))//some section has comment.                    {                         for(str = sin.) ReadLine (); str! =NULL&&!str. Trim (). StartsWith ("["); str = sin. ReadLine ())//loop for Get string, until to next, or end of file.                        {                            if(! String.IsNullOrEmpty (str. Trim ()) &&!str. Trim (). StartsWith (";"))//Drop the comment line and empty line.//Remove the restriction of name-value, because there is no = case. 20100309.str. Contains (' = ') && only get the name-value pair line.{string[] keyvalues= str. Split ('='); if(section. Equals ("[SourceDisksNames"))                                {                                    string[] Nocommentvalues = keyvalues[1]. Split (';'); stringRealvalue = nocommentvalues[0].                                    Trim (); String[] Sourcediskcfg= Realvalue.split (',');//Disk-description[,[tag-or-cab-file],[unused],[path],[flags][,tag-file]] (tag-file:windows XP and later versions of Windows)String Diskpath =String.Empty; if(Sourcediskcfg.length >3) Diskpath= sourcediskcfg[3].                                    Trim (); if(Diskpath. StartsWith ("\"")) Diskpath=removequotes (Diskpath); if(! String.IsNullOrEmpty (Diskpath) && Diskpath. StartsWith (".")) Diskpath= Diskpath. Substring (Diskpath. IndexOf ('\\')); //20150112                                    if(! String.IsNullOrEmpty (Diskpath) &&!diskpath. StartsWith ("\\")) Diskpath="\\"+Diskpath; Keytovalue.add (keyvalues[0].                                Trim (), Diskpath); }                                Else                                {                                                          string[] Nocommentvalues = keyvalues[1]. Split (';'); stringRealvalue = nocommentvalues[0].                                    Trim (); Keytovalue.add (keyvalues[0].                                Trim (), realvalue); }                            }                        }                         Break; }                }            }            returnKeytovalue; }
View Code

C # loops through file streams, reads by rows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.