Re: Question about the split function
- From: "Yunus Emre ALPÖZEN [MVP]" <yemre>
- Date: Thu, 26 Jan 2006 21:57:36 +0200
Let me fix your code...
First of all if you are trying to parse a file which is less than 10 MB u
may use File.OpenText otherwise u should use StreamReader
public void ReadFromFile(string pFilename)
{
StreamReader sr = null;
String sLine;
String[] stringData;
try
{
sr = File.OpenText(pFilename);
while (sr.Peek()>=0)
{
sLine= sr.ReadLine();
stringData= sLine.Split(':'); // Only available with 2.0
if (stringData.Length > 1)
Console.WriteLine("{0}\t{1}",stringData);
}
}
finally
{
if (sr != null)
sr.Close();
}
}
Also, u can access "mybook" using stringData[1]
--
HTH
Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET
Microsoft .NET & Security MVP
<needin4mation@xxxxxxxxx> wrote in message
news:1138304266.165749.54600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi, I am trying to parse a colon delimited text file.
>
> Assume these as examples:
>
> Book:mybook
> Video:myvideo
> Name:myname
>
>
> When I use this:
>
> ReadFromFile("c:\\Inetpub\\wwwroot\\myfile.txt");
> }
> public void ReadFromFile(string filename)
> {
> StreamReader SR;
> string S;
> string[] myStr;
> SR=File.OpenText(filename);
> S=SR.ReadLine();
> while(S!=null)
> {
> myStr = S.Split(new char[] { ':' });
> Response.Write(myStr[0] + "<BR>");
> S=SR.ReadLine();
> }
> SR.Close();
> }
>
> On my web page I get this:
>
> Book
> Video
>
> What I am trying to get is the stuff on the other side of the colon.
> How can I get either the data on the other side of the colon or just
> the entire line?
>
> Thank you for any help.
>
.
- Follow-Ups:
- Re: Question about the split function
- From: chris martin
- Re: Question about the split function
- References:
- Question about the split function
- From: needin4mation
- Question about the split function
- Prev by Date: Re: Question about the split function
- Next by Date: Re: Can I change my setup according to the configuration
- Previous by thread: Re: Question about the split function
- Next by thread: Re: Question about the split function
- Index(es):
Relevant Pages
|
Loading