hello guys, its nice to belong in this forum.
please help me, i do not know what to do next in my program...
i am just noob in C#, i have an understanding on some basics of Java lagnguage but i decided to switch to C#... so i do not totally understand what is going on here...
private void myMenuToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream myStream = null;
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = "c:\\";
open.Filter = "Text File|*.txt";
if (open.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = open.OpenFile()) != null)
{
using (myStream)
{
//////////////////////////////////////////////////////////////
//this is my problem... what i plan to do here is to get strings from a text
//file, inside the text file are some information of persons separated by
//this symbol "|"(every line is a new person), then save it
//(somewhere) so that the information of a person will be available to
// display on a textbox in the windows form.
//inside the text file is:
////////////////////////////////////////////////////////////////////////////
//Jack|Jack Black|10-20-2010|balck.com //
//Harry|Harry Potter|01-10-1985|harrypotter.com //
//Jo|Joshua White|02-21-1990|white.com //
//and many others.... //
/////////////////////////////////////////////////////////////////////////////
// Im stuck here, i dont really know what to do next...
StreamReader reader = new StreamReader(open.FileName);
string[] content = reader.ReadLine().Split(new char[] { '|' });
}
thanks in advance...
C# windows form problem
Started by zkil_cc, Jun 30 2010 06:12 AM
5 replies to this topic
#1
Posted 30 June 2010 - 06:12 AM
|
|
|
#2
Posted 30 June 2010 - 10:32 AM
You need to write a method that is a custom parser for that type of information. Have a static splitter string that matches "|" and parse the text as you read it. You can use the String.split method and get an array of the items and then populate the text boxes accordingly. You will need to create a parser class and then new up an instance of that parser in your code behind file.
If you need more information let me know.
If you need more information let me know.
-CDG10620
Software Developer
Software Developer
#3
Posted 01 July 2010 - 07:46 AM
Splitting a string based on a special character:
string x = "item1|item2|item3|item4";
string[] a = x.Split("|");
//a will contain:
//a[1] - item1
//a[2] - item2
//etc...
Just make a method that does you job. Where exactly do your compiler returns an error?
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#4
Posted 01 July 2010 - 07:48 AM
Quote
Im stuck here, i dont really know what to do next...
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#5
Posted 01 July 2010 - 03:50 PM
yup, i do not know how to write the code... just like what i said, im not that experienced in programming...:confused:
i think this will do the job but what if i want to assign one line of information to a specific person(see the content of the sample text file), what i mean is...
the first line of string will be assigned to x:
string x = "item1|item2|item3|item4";
string[] a = x.Split("|");
the second line of text will be assigned to y:
string y = "item1|item2|item3|item4";
string[] b =y.Split("|");
and so on...
Is that possible? so that i can print out item1 of a or item2 of b...?
Quote
Code:
string x = "item1|item2|item3|item4";
string[] a = x.Split("|");
//a will contain:
//a[1] - item1
//a[2] - item2
//etc...
string x = "item1|item2|item3|item4";
string[] a = x.Split("|");
//a will contain:
//a[1] - item1
//a[2] - item2
//etc...
the first line of string will be assigned to x:
string x = "item1|item2|item3|item4";
string[] a = x.Split("|");
the second line of text will be assigned to y:
string y = "item1|item2|item3|item4";
string[] b =y.Split("|");
and so on...
Is that possible? so that i can print out item1 of a or item2 of b...?
#6
Posted 02 July 2010 - 07:19 AM
//ReadToEnd() or ReadAllLines(), I forgot...
foreach (string line in x.ReadToEnd())
{
string[] a = x.Split("|");
//Do stuff with a
}
Or, you can create an array with string arrays.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics


Sign In
Create Account

Back to top









