How to parse configuration file data

Source: Internet
Author: User

Some parameters need to be saved to files during system creation,

The format is as follows:

 

Username = Tom; </P> <p> sex = male; </P> <p> age = 50; </P> <p>

 

It is troublesome to get the username value. I wrote a method myself.

Put these values in dictionary, and all keys are in lowercase.

 

/// <Summary>
/// Parse the configuration file data
/// </Summary>
/// <Param name = "data"> data read from a file or memory </param>
/// <Returns> </returns>
Private Static dictionary <string, string> analyseconfig (byte [] data)
{
String allstr = new system. Text. asciiencoding (). getstring (data );
// Allstr = allstr. Replace ('/N ','');
Allstr = allstr. Replace ('/R ','');
String [] Config = allstr. Split (New char [] {'/N ',';'});
String [] KV = {"",""};
Dictionary <string, string> dconfig = new dictionary <string, string> ();
For (INT I = 0, Ln = config. length; I <ln; I ++)
{
If (! String. isnullorempty (config [I])
{
KV = config [I]. Split (New char [] {'= '});
Try
{
Dconfig. Add (Kv [0]. tolower (), Kv [1]);
}
Catch (system. indexoutofrangeexception ex)
{
}

}
}
Return dconfig;
}

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.