-1

Possible Duplicate:
Reading/writing INI file in C#

I have a textfile to store certain data for my parser. The data stored looks something like this:

[Yandex]
Hostname=http://yandex.ru
Query=yandsearch?text=[QUERY]&lr=213
LinksMask=<a class="b-serp-item__title-link" tabindex="2"[...]href="[LINK]" onmousedown=
TotalPages=100
NextPage=<a id="next_page" class="b-pager__next" href="[LINK]" onmousedown
NextPage2=<a id="next_page" class="b-pager__next" href="[LINK]" onmousedown
CaptchaURL=showcaptcha?retpath
CaptchaImage=captchaimg?
CaptchaField=rep
[Google Classic]
Hostname=http://[GOOGLEHOST]
Query=search?as_q=[QUERY]&num=100&hl=en&output=ie&filter=0
LinksMask=<li class="g"><h3 class="r"><a[...]href="[LINK]"
TotalPages=10
NextPage=<td class="b" style="text-align:left"><a href="[LINK]"
NextPage2=</font></a></td><td><a href="[LINK]"
CaptchaURL=
CaptchaImage=
CaptchaField=

I want to parse out the data under each [XXXX] and save the Hostname=, Query=, etc into strings..

What would the easiest way be to accomplish this?

Not looking to store the data in another way than textfile, i want it to be very easy to change for the user :)

Community
  • 1
  • 1
Jacqueline
  • 481
  • 2
  • 11
  • 20

1 Answers1

0

This is known as ini file format, and you can use the Win32 API GetPrivateProfileString to read it, using P/Invoke to call the API. Please see here for more details. The article linked to by L.B. gives better/easier solutions though.

Community
  • 1
  • 1
Polyfun
  • 9,479
  • 4
  • 31
  • 39