i have a text file that is divided into blocks:
#1
1:animal
2:food
3:moves
4:oxygen
#2
1:eats:2
2:breaths:2
3:can:1
4:is a:1
#3
1:1:2
1:3:3
1:2:4
and the following program that displays block by block: - StreamReader streamReader = new StreamReader("G:\\LAB123\\LABWORK2.txt");
-
int block = 0;
-
while (!streamReader.EndOfStream)
-
{
-
string line = streamReader.ReadLine().Trim();
-
if (line.CompareTo("") == 0)
-
{
-
continue;
-
}
-
if (line.CompareTo("#1") == 0)
-
{
-
block = 1;
-
continue;
-
}
-
if (line.CompareTo("#2") == 0)
-
{
-
block = 2;
-
continue;
-
}
-
if (line.CompareTo("#3") == 0)
-
{
-
block = 3;
-
continue;
-
}
-
if (block == 1)
-
{
-
string[] pairs = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
-
if (pairs.Length == 2)
-
{
-
int code = Convert.ToInt32(pairs[0].Trim());
-
string name = pairs[1].Trim();
-
Console.WriteLine("code = {0}, name = '{1}'", code, name);
-
}
-
}
-
if (block == 2)
-
{
-
string[] pairs = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
-
if (pairs.Length == 3)
-
{
-
int code = Convert.ToInt32(pairs[0].Trim());
-
string name = pairs[1].Trim();
-
int type = Convert.ToInt32(pairs[2].Trim());
-
Console.WriteLine("code = {0}, name = '{1}', type = {2}", code, name, type);
-
}
-
}
-
if (block == 3)
-
{
-
-
string[] pairs = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
-
if (pairs.Length == 3)
-
{
-
int code = Convert.ToInt32(pairs[0].Trim());
-
int connection = Convert.ToInt32(pairs[1].Trim());
-
int types = Convert.ToInt32(pairs[2].Trim());
-
Console.WriteLine("code = {0}, connection = {1}, types = {2}", code, connection, types);
-
}
-
}
my problem is am supposed to add a verification code so that if i put a string e.g 1:?:? it returns the block where the string is found and gives of all possible answers please help
2 3087
I have no idea what you're trying to do. Is this homework?
The code above displays my text file into block 1,2,3.but i need to search a specific string eg 1:?:? and related terms like 1:1:2, 1:eat:2, will be displayed on screen.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Imran |
last post by:
hello all, I have to parse a text file and get some value in that.
text file content is as follows.
####TEXT FILE CONTENT STARTS HERE #####
/start
first
0x1234
AC
/end
|
by: semi |
last post by:
Hello,
I am using VS C++ to make a gui that displays a text file contents from
main dialog. So I created main dialog and another dialog for text file
viewer. From the main dialog, I call text...
|
by: jlea |
last post by:
Does anyone know of a nice little .NET class that throws the contents of a
supplied file to a scrollable window/form/control?
|
by: Amjad Farran |
last post by:
What is the easiest way to display in a table, a delimited
text data saved in a text file?
I need an idea so that I can research it!
Amjad
|
by: Rosario Morgan |
last post by:
Hello
Help is great appreciated in advance.
I need to loop through a file 6000 bytes at a time. I was going to
use the following but do not know how to advance through the file 6000
bytes at...
|
by: sugard |
last post by:
Abstract Class, Inheritance, Polymorphism, File Handling, Exception Handing
A program is to be devised for a university to work out whether or not, a student or a professor, is
outstanding. The...
|
by: CAM123 |
last post by:
I have added:
<br><xsl:value-of select="Line" /></br>
to my XSLT stylesheet to get a line per repeating block. When I view the output as XML it looks perfect - one line per block. However...
|
by: paragguptaiiita |
last post by:
I have one problem regarding displaying text from XML file.
I have a XSL variable named $p = (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0) (5.63 -0.02 0) (6.63 -0.02...
|
by: paragguptaiiita |
last post by:
I have one problem regarding displaying text from XML file.
I have a XSL variable named $p = (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0) (5.63 -0.02 0) (6.63 -0.02...
|
by: dm3281 |
last post by:
Hello, I have a text report from a mainframe that I need to parse.
The report has about a 2580 byte header that contains binary information
(garbage for the most part); although there are a...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |