My Computer Forum Computer Science Forum

Go Back   My Computer Forum > Computer Science Forum > Programming

Programming Programming Languages, Interpreters, and Compilers - Assembly, Declarative, Machine, Object Oriented, Iterative


Reply
 
LinkBack Thread Tools Display Modes
December 11th, 2008, 01:46 PM   #1
 
Joined: Dec 2007
Posts: 37
Reading formatted text in C#

Hello everybody. I've just been wondering if you know how to read some data from a text file that's formatted in a certain way? For example, if I have a text file that looks like this:

125621 11212
333542 3354
999433 22211

how would one load this? Also, I should get a numerical representation of the data, not a string.
milin is offline  
 

My Computer Forum is free to register and we welcome everyone!

December 11th, 2008, 03:45 PM   #2
 
Joined: Dec 2007
Posts: 232
Re: Reading formatted text in C#

Loop until EOF, reading in the next line as the variable "line". Then do
string[] txt = line.Split(charArrayContainingOnlyASpace);
int a = int.Parse(txt[0]);
int b = int.Parse(txt[1]);

with appropriate error-trapping, of course.
CRGreathouse is offline  
December 12th, 2008, 09:17 AM   #3
 
Joined: Dec 2007
Posts: 37
Re: Reading formatted text in C#

Thanks.. Will try.. But let me ask you something. What does the Parse class do, exactly? I mean, to what extent does it function and what are it's abilities?
milin is offline  
December 14th, 2008, 03:43 PM   #4
 
Joined: Dec 2007
Posts: 232
Re: Reading formatted text in C#

Quote:
Originally Posted by milin
Thanks.. Will try.. But let me ask you something. What does the Parse class do, exactly? I mean, to what extent does it function and what are it's abilities?
int.Parse just changes a number stored in a string to the int it represents. int.Parse("123") is 123.
CRGreathouse is offline  
December 15th, 2008, 05:03 AM   #5
 
Joined: Dec 2007
Posts: 37
Re: Reading formatted text in C#

I figured it out when I tried it.. Than you for your help..
milin is offline  
Reply

  My Computer Forum > Computer Science Forum > Programming

Tags
formatted, reading, text



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solution for recovery of formatted FAT disk? arnima OS Architecture 0 September 16th, 2013 09:56 PM
Moving files/adding text to files (VB/*.bat) Doug4347 Computer Science 0 December 17th, 2012 10:04 AM
Generate a formatted word document jj.davies Programming 3 December 5th, 2012 01:01 AM
Reading email SidT Programming 4 June 11th, 2009 11:06 PM
Visual Studio -- text boxes CRGreathouse Programming 3 December 9th, 2008 12:50 AM





Copyright © 2018 My Computer Forum Forum. All rights reserved.