List Info

Thread: C-Sharp (C#) Group: Reading from text file.




C-Sharp (C#) Group: Reading from text file.
user name
2006-02-10 23:27:49
Hi,

  I'm trying to make a simple program, which reads separate
words from
file and puts them in some data structure. All words are
separated with
commas. I'm new to c# and don't know yet how to manipulate
strings.
What data types or methods I should use to get results?

example file:
"u",	320,	630,	2560,	6,	13,	48
"a",	780,	1300,	2460,	6,	8,	30
"o",	500,	940,	2420,	3,	12,	35
"as",	720,	1060,	2420,	3,	8,	27
"o/",	430,	1580,	2260,	2,	24,	36

C-Sharp (C#) Group: Re: Reading from text file.
user name
2006-02-10 23:33:20
An easy way would be split on commas and trim spaces with a
regex using
System.Text.Regular...

Quick and dirty example to get you started... you should
look up regular
expressions and take a look at all the members of the string
class,
there are plenty of useful things there.

foreach(string s in myLineFromFile.Split(','))
	myArrayList.Add(Regex.Replace(s, "^ +"));


That would store every item in the array list. 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.15.5/256 - Release
Date:
2/10/2006
 

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )