Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:12:21+00:00 2026-05-30T19:12:21+00:00

I read a list of numbers from a text document and saved them in

  • 0

I read a list of numbers from a text document and saved them in a List<String> and I am trying to convert those numbers into a List<int>. The numbers are separated by spaces. Here is what I tried, assuming Numbers is the String list:

List<int> AllNumbers = Numbers.ConvertAll<int>(Convert.ToInt32);

When I try to use this is says “Input string was not in a correct format.”

What is the correct way to convert a List<String> into a List<int>?

SAMPLE:

            string numbers = File.ReadAllText("numbers.txt");
            string[] allNumbers = numbers.Split(new char[] { ' ', '\t', '\r', '\n' },    StringSplitOptions.RemoveEmptyEntries);
            List<string> List = new List<string>();
            List.AddRange(allNumbers);

I then want to take the List allNumbers and convert it to a List of integers.

The text file looks like this:

10 12 01 03 22….ect

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:12:22+00:00Added an answer on May 30, 2026 at 7:12 pm

    It looks like your numbers are in a single string separated by spaces if so you can use Linq:

    List<int> allNumbers = numbers.Split(' ').Select(int.Parse).ToList();
    

    If you really have a List<string> numbers already simply:

    List<int> allNumbers = numbers.Select(int.Parse).ToList();
    

    Or finally, if each string may contain multiple numbers separated by spaces:

    List<int> allNumbers  = numbers.SelectMany(x=> x.Split(' ')).Select(int.Parse).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read a list of items from a text file and format
I am trying to read a large list of English words from a text
Hey, I've been working on this problem to read numbers from a text file
I am Trying to read data from text files and save tokens in SQLite
I want to read list of applications from the Applications folder on Mac using
In the code below i`m trying to read a list of selected projects and
Is it good to use such approach for keeping read-only list of string, for
This loads a set of values from an XML file and places them into
I am writing a program to read lines of text from 5 files and
I want to be able to read from an unsorted source text file (one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.