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 6063191
In Process

The Archive Base Latest Questions

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

I have an input as 2:{{2,10},{6,4}} I am reading this as string input =

  • 0

I have an input as

2:{{2,10},{6,4}} 

I am reading this as

string input = Console.ReadLine();

Next this input has to be passed to a function

GetCount(int count, int[,] arr)
{

}

How can I do so using C#?

Thanks

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

    You could use RegularExpressions for extracting in an easy way each token of your input string. In the following example, support for extra spaces is included also (the \s* in the regular expressions).

    Remember that always is a great idea to give a class the responsibility of parsing (in this example) rather than taking an procedural approach.

    All the relevant lines are commented for better understanding.

    Finally, i tested this and worked with the provided sample input strings.

    using System;
    using System.Text.RegularExpressions;
    
    namespace IntPairArrayParserDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                var input = "2:{{2,10},{6,4}}";
                ParseAndPrintArray(input);
    
                var anotherInput = "2  : { { 2 , 10 } , { 6 , 4 } }";
                ParseAndPrintArray(anotherInput);
            }
    
            private static void ParseAndPrintArray(string input)
            {
                Console.WriteLine("Parsing array {0}...", input);
    
                var array = IntPairArrayParser.Parse(input);
    
                var pairCount = array.GetLength(0);
                for (var i = 0; i < pairCount; i++)
                {
                    Console.WriteLine("Pair found: {0},{1}", array[i, 0], array[i, 1]);
                }
                Console.WriteLine();
            }
        }
    
        internal static class IntPairArrayParser
        {
            public static int[,] Parse(string input)
            {
                if (string.IsNullOrWhiteSpace(input)) throw new ArgumentOutOfRangeException("input");
    
                // parse array length from string
                var length = ParseLength(input);
    
                // create the array that will hold all the parsed elements
                var result = new int[length, 2];
    
                // parse array elements from input
                ParseAndStoreElements(input, result);
    
                return result;
            }
    
            private static void ParseAndStoreElements(string input, int[,] array)
            {
                // get the length of the first dimension of the array
                var expectedElementCount = array.GetLength(0);
    
                // parse array elements
                var elementMatches = Regex.Matches(input, @"{\s*(\d+)\s*,\s*(\d+)\s*}");
    
                // validate that the number of elements present in input is corrent
                if (expectedElementCount != elementMatches.Count)
                {
                    var errorMessage = string.Format("Array should have {0} elements. It actually has {1} elements.", expectedElementCount, elementMatches.Count);
                    throw new ArgumentException(errorMessage, "input");
                }
    
                // parse array elements from input into array
                for (var elementIndex = 0; elementIndex < expectedElementCount; elementIndex++)
                {
                    ParseAndStoreElement(elementMatches[elementIndex], elementIndex, array);
                }
            }
    
            private static void ParseAndStoreElement(Match match, int index, int[,] array)
            {
                // parse first and second element values from the match found
                var first = int.Parse(match.Groups[1].Value);
                var second = int.Parse(match.Groups[2].Value);
    
                array[index, 0] = first;
                array[index, 1] = second;
            }
    
            private static int ParseLength(string input)
            {
                // get the length from input and parse it as int
                var lengthMatch = Regex.Match(input, @"(\d+)\s*:");
                return int.Parse(lengthMatch.Groups[1].Value);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to rewrite Webconfig connection string at runtime.I have input textbox for Server,UserName and
I have this input text: <html><head><meta http-equiv=content-type content=text/html; charset=utf-8></head><body><table cellspacing=0 cellpadding=0 border=0 align=center width=603>
I have a problem with reading empty string in C. I want to read
I have a Pygame program that needs text input. The way it does this
this is the code that i have found in the internet for reading the
I am reading a file like this: char string[256]; std::ifstream file( file.txt ); //
I am reading this bison introduction. I have two questions and it will be
I have a problem reading uploaded XML file to the string instead of file.
After reading the android documentation about String, which includes this: This class is implemented
In the code below I have a StreamReader reading from a network stream. This

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.