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

  • SEARCH
  • Home
  • 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 6064759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:18:55+00:00 2026-05-23T09:18:55+00:00

I have an input string that looks something like this: 4 Bob 32 Joe

  • 0

I have an input string that looks something like this:

4 Bob 32 Joe 64 Sue 123 Bill 42

Where the 4 indicates the number of string integer pairs to follow. My current way of processing this looks something like this:

var strings = input.Split(' ');
int count = Int32.Parse(strings[0]);
for ( int i = 0; i < count; i++ )
{
  string name = strings[count*2 + 1];
  int number = Int32.Parse(strings[count*2 + 1]);
  ProcessPerson(name, number);
}

This feels quite cumbersome. Is there some library in C# that can wrap a string and give me services like “readInt” and “readString”. I would ultimately like to have something like:

int count = input.ReadInt();
for(int i = 0; i<count; i++)
{
  ProcessPerson(input.ReadString(), input.ReadInt());
}

It doesn’t look like that much of an improvement in this case, but my actual object model is a bit more complicated. I know other languages have facilities to o things like this, but I can’t recall any .net libraries to simply read from the front of a string.

  • 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-23T09:18:55+00:00Added an answer on May 23, 2026 at 9:18 am

    You could easily write such a “library” yourself:

    class Parser
    {
        private readonly Queue<string> m_parts;
    
        public Parser(string s)
        {
            m_parts = new Queue<string>(s.Split(' '));
        }
    
        public string ReadString()
        {
            return m_parts.Dequeue();
        }
    
        public int ReadInt32()
        {
            return int.Parse(ReadString());
        }
    }
    

    If the string could be large, or you are reading it from a stream, you have to do the splitting yourself:

    class StreamParser
    {
        private readonly TextReader m_reader;
    
        public StreamParser(string s)
            : this(new StringReader(s))
        {}
    
        public StreamParser(TextReader reader)
        {
            m_reader = reader;
        }
    
        public string ReadString()
        {
            var result = new StringBuilder();
            int c = m_reader.Read();
            while (c != -1 && (char)c != ' ')
            {
                result.Append((char)c);
                c = m_reader.Read();
            }
    
            if (result.Length > 0)
                return result.ToString();
    
            return null;
        }
    
        public int ReadInt32()
        {
            return int.Parse(ReadString());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a string/integer that looks like 123 , how can I convert
I have a model that looks something like this class Post(models.Model): id = models.IntegerField(unique=True,
So I have a a text file that looks something like this: public >ret
I have a form that looks something like this <form action=# class=ajax_form method=post id=comment_form
I have a string that will look something like this: I'm sorry the code
I have a mysql table that looks something like this: Row 1: 'visitor_input_id' =>
I have a dict of configuration variables that looks something like this: self.config =
I have a string input = "maybe (this is | that was) some ((nice
I have a view model that has a property that looks like this Property
On my web pages I have source that looks like this: <div id=opt_3 >A)</div>

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.