Jump to content
  • Advertisement
Sign in to follow this  
Jeffsg605

C Sharp File IO

This topic is 2565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do you read a text file of integers into an array? I'm have a map in text format for XNA. I'm new to C Sharp and All I can find is how to read in strings. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement

How do you read a text file of integers into an array? I'm have a map in text format for XNA. I'm new to C Sharp and All I can find is how to read in strings. Thanks in advance.


Assuming the file is newline separated ints and only ints:


List<int> ints = new List<int>(File.ReadAllLines(filename).Select(s => int.Parse(s)));


Otherwise you'll need to read in the text and then break it up into chunks and handle bad input (like not ints, or extra whitespace or...)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!