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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:27:37+00:00 2026-06-11T01:27:37+00:00

I have a string variable that contain [l=9;f=0;r=5;p=2] . There are may be a

  • 0

I have a string variable that contain [l=9;f=0;r=5;p=2]. There are may be a more than one:[l=9;f=0;r=5;p=2],[l=9;f=0;r=6;p=2].

I want to get List of Tuple<int,int,int>, where item1 = value of l, item2= value of r, item3=value of p. What is best approach to do this?
My code:

  // split string
    var splittedFormatedSeats = Regex.Matches(formatSeats, @"\[.+?\]")
                            .Cast<Match>()
                            .Select(m => m.Value)
                            .ToList();


     IList<Tuple<int,int,int>> fullSeat = new List<Tuple<int, int, int>>();
       foreach (var splittedFormatedSeat in splittedFormatedSeats)
       {

          ...
       }

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-06-11T01:27:38+00:00Added an answer on June 11, 2026 at 1:27 am

    I would adopt another strategy. First, split subcomponents of your string

    var components = formatSeats.Split(',');
    

    This will give you an array of string. This will be far more efficient to parse small chunks of strings instead of a big string.

    You can then use either a Regex to extract the values or a simple code like this :

    foreach(var component in components)
    {
        var parts = component.Trim("[]".ToCharArray()).Split(';');
    
    }
    
    var results = from component in components
                  let c = component.Trim("[]".ToCharArray())
                                   .Split(';')
                                   .Select(c=>int.Parse(c.SubString(2))
                  select new { l = c[0], f=c[1], r=c[2], p = c[3] };
    

    This will produces an enumeration of an anonymous type.

    foreach(var x in results)
    {
        Console.WriteLine("{0} / {1} / {2} / {3}", x.l, x.f, x.r, x.p);
    }
    

    If you actually need a Tuple simply change the code to :

    var results = from component in components
                  let c = component.Trim("[]".ToCharArray())
                                   .Split(';')
                                   .Select(c=>int.Parse(c.SubString(2))
                  select new Tuple<int,int,int,int>{ l = c[0], f=c[1], r=c[2], p = c[3] };
    

    I would however, advocate for writing a small struct to simplify the code and raise its readability.

    public struct MyValue
    {
         private readonly int m_L; 
         public int L { get {return m_L; } }
    
         private readonly int m_F; 
         public int F { get {return m_F; } }
    
         private readonly int m_R; 
         public int R { get {return m_R; } }
    
         private readonly int m_P; 
         public int P { get {return m_P; } }
    
         public MyValue(int l, int f, int r, int p)
         {
             m_L = l;
             m_F = f;
             m_R = r;
             m_P = p;
         }
    }
    ....
    
    
    var results = from component in components
              let c = component.Trim("[]".ToCharArray())
                               .Split(';')
                               .Select(c=>int.Parse(c.SubString(2))
              select new MyValue(c[0],c[1],c[2],c[3]);
    

    Finally, if the string always have this form, you could avoid using the Regex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have strings that contain a variable number of leading hyphens and which may
I have a variable that can either contain a list of strings or a
I have a variable that contains the following JSON string: { 0 : Jun
I have a query string that contains a variable like this $field_name = 'features';
I have a variable $next which contains strings that might contain parenthesis e.g trna(tgc)
I have javascript string variable with var sttr=We prefer questions that can be answered
I have a large string in a variable that includes a whole bunch of
I have a variable that has this string: <DIV><SPAN style=FONT-FAMILY: Tahoma; FONT-SIZE: 10pt>[If the
I have three variables that may or may not contain data. let's call them
In Java, suppose I have a String variable S, and I want to search

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.