Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I have a txt file like this.

[BasicText]
Some text here in multiple lines...
Some text here in multiple lines...
Some text here in multiple lines...

[FooterText]
Some text here in multiple lines...
Some text here in multiple lines...
Some text here in multiple lines...

[Head]
Hide = 1

How I can read and write the text in these two sections and how
I can read and write the hide option in Visual Basic .net

Thank you.
Posted
Updated 6-Apr-15 8:45am
v2
Comments
CHill60 6-Apr-15 10:33am    
What have you tried?
ZurdoDev 6-Apr-15 10:35am    
Use the System.IO.File class. https://msdn.microsoft.com/en-us/library/system.io.file%28v=vs.110%29.aspx
Sergey Alexandrovich Kryukov 6-Apr-15 13:51pm    
Just read it. What's the problem, exactly? What have you tried so far?
—SA

Here is an example of reading text file[^]

Once you have the data look for the section headers.

Alternatively have a look at this CP article INI Reader / Writer Class for C#, VB.NET, and VBScript[^]
 
Share this answer
 
Comments
Maciej Los 6-Apr-15 14:45pm    
+5
Hi, you can try .NET library I created for INI files processing. You can find sample codes for both reading and writing sections and keys with VB.NET.
For example:
VB
Dim ini As New IniFile()

' Add new section.
ini.Sections.Add("Section's Name")

' Add new section with some keys.
Dim anotherSection = ini.Sections.Add("Another Section's Name")
anotherSection.Keys.Add("Key's Name", "Key's Value")
anotherSection.Keys.Add("Another Key's Name", "Another Key's Value")
 
Share this answer
 
I have already try this article

INI Reader / Writer Class for C#, VB.NET, and VBScript[^]

but i have to insert section and key and it doesn't work cuz I must insert section and key but in most cases i have only sections. and in some cases I have both.

I have to say that the text file created automatically from another app and i can't do anything for the format of the file.

I just want to read and write this file.
 
Share this answer
 
Comments
CHill60 6-Apr-15 15:12pm    
No - just create a section with zero keys. The file you have is standard "INI" style format and the code in that article will work - you just have to put a little of your own effort into it.
For you information - I only spotted this "response" because I saw there was a 2nd solution to a post I had answered. If you want to respond to a poster use the "Have a Question or Comment" link next to their post, or the "Reply" link if responding to a comment

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900