×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Read File and get specific text from line

Read File and get specific text from line

Read File and get specific text from line

(OP)
Hellow again,

I need to read a file(.txt) and get a particular row. the file containes a sngle row per order shipped.

This an sample of how the data looks. For this sample file I need to read the text file by using the tracking number 848257570000106 and when it findthe row with the tracking number I want either

A) the entire row or
B) the value between "1528," and "1596",

In this example I would either need the entire line or 706

CODE -->

'0,"120"1,"MPS Ship"10,"344002738"29,"848257570000080"34,"660"35,"46"1528,"325"1596,"0"1598,""'
'0,"120"1,"MPS Ship"10,"344002738"29,"848257570000093"34,"265"35,"46"1528,"362"1596,"0"1598,""'
'0,"120"1,"MPS Ship"10,"344002738"29,"848257570000106"34,"879"35,"46"1528,"706"1596,"0"1598,""'
'0,"120"1,"MPS Ship"10,"344002738"29,"848257570000128"34,"155"35,"46"1528,"952"1596,"0"1598,""'
'0,"120"1,"MPS Ship"10,"344002738"29,"848257570000134"34,"681"35,"46"1528,"574"1596,"0"1598,""' 

The end user woud supply an order number in a windows form which will populate the tracking numbers in a dropdown box for this orders packages. He will select a tracking number and this is the value that will be searched in the text file.

is this possible nad if so what would be the best way to do it. I am alos open to other sugegstion on how I cna get ths value from the text file

Thanks in advance
RJL

RE: Read File and get specific text from line

Hi RJL,

sounds pretty straight forward.
How abou something like this:

CODE

using (StreamReader sr = new StreamReader(pfad + "\\pk.xml"))
{
    string line = "";
    string trackingnumber="848257570000106";
    while (!sr.EndOfStream)
    {
        line = sr.ReadLine();
        if (line.IndexOf(trackingnumber) > 0)
        {
            //line now has the entire line
            string mycode = line.Substring(line.IndexOf("1528,") + 5, line.IndexOf("1596"));
            mycode = mycode.TrimStart(' ', '\"');
            mycode = mycode.TrimEnd(' ', '\"');
            break;
        }
    }
} 

Would that do it?

Cheers,
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: Read File and get specific text from line

Could this line string mycode = line.Substring(line.IndexOf("1528,") + 5, line.IndexOf("1596"));

not be extended to string mycode = line.Substring(line.IndexOf("1528,\"") + 5, line.IndexOf("\"1596"));

and thus negate the need for the two Trim statements.

I don't have c# on this machine so I can't check, but it seems a simpler approach to me.

RE: Read File and get specific text from line

I guess so.
bigcheeks

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: Read File and get specific text from line

RJL, do you ever respond to your threads??

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close