Click here to Skip to main content
15,898,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i wonder if you can help me. i have a text file which i just need to look up one value and then display it in a label.
here is the sample of the text snippet it is always on the 5th line of the file, in the label i only need to display "KALLIE-L"

[Operater]
Name=KALLIE-L

i get an Index was outside the bounds of the array. error on lbloperator.text line.

i know i am doing it wrong but i am not sure how to change or get it right.

VB
Dim FileContents() As String = IO.File.ReadAllLines("C:\TEST.INI")
        For I = 0 To FileContents.Length - 1

            Dim LineParts() As String = FileContents(I).Split("Name=")

            lbloperator.Text = LineParts(1)


any assistance pointing will be helpfull
Posted

1 solution

Try this:
C#
StreamReader file = null;
try
{
    file = new StreamReader(@"C:\TEST.INI");
    while ((line = file.ReadLine()) !=null)
    {
        string regMatch = "MyString"; //Your Text To search
        if(Regex.IsMatch (line, regMatch))
        {
            if(line.Split("Name=")[1].ToString().Trim() != "")
                lbloperator.Text = line.Split("Name=")[1].ToString().Trim();
        }
    }
}


--Amit
 
Share this answer
 
Comments
Member 9742322 15-Mar-13 5:23am    
thank you ,

i get the following error though, line does not exist in current context.
while ((line = file.ReadLine()) !=null)
_Amy 15-Mar-13 5:55am    
Declare the line variable.

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