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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:31:43+00:00 2026-05-26T21:31:43+00:00

I am trying to rewrite TCL code in C#. The code of concern is

  • 0

I am trying to rewrite TCL code in C#. The code of concern is the following:

set list [regexp -all -inline -line {.+\d+.+\d+} $string]

In this case the regexp procedure returns a list of all matches in the string after which I am sorting this list of strings with another expression based on a numeric value in the end of the string:

set sortedList [lsort -decreasing -integer -index end  $list]

The question is, how to achieve the same in C#? I tried the following:

MatchCollection mc = Regex.Matches(inputString, regexPattern, RegexOptions.Multiline);

As I found however, I cannot sort a matchcollection directly in C# so I copied every match to an array:

string[] arrayOfMatches = new string[mc.Count];

for (int i = 0; i < mc.Count; i++)
{
arrayOfMatches[i] = mc[i].Groups[1].Value;
}

However, when I try to sort the arrayOfMatches array, I do not see the Sort method available. What am I missing and am I moving in the right direction? 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-26T21:31:44+00:00Added an answer on May 26, 2026 at 9:31 pm

    The Array.Sort() method is static, so you have to call it like this:

    Array.Sort(arrayOfMatches, comparison);
    

    Where comparison is either a delegate that can compare two strings or an implementation of IComparer<T> that can do the same.

    But it might be easier to use LINQ:

    var matches =
        from Match m in mc
        let value = m.Groups[1].Value
        let numericValue = int.Parse(value)
        orderby numericValue descending
        select value;
    

    This assumes the whole value is the number. If I understand you correctly and you want to get a numeric value from the end of the string, you would have to add code to do that.

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

Sidebar

Related Questions

I am trying to rewrite this messy code, so that I only make one
I have this code I'm trying to rewrite to c# from a vbs script.
I'm trying to rewrite the following java method that return a list of objects(hibenrate
I'm trying to rewrite this url: http://www.example.com/user.php?user=username into http://example.com/username I'm using this code in
I'm trying to rewrite following snippet in clojure, but it all comes out ugly,
I am trying to rewrite this code without the or operator. if((/^\s*field\s+{\s*$/)||(/^\s*field\s+{\s*\/\/.*$/) { #
I am trying to rewrite an url with GET-data from a form. This works
I'm trying to rewrite a url of this: http://www.foo.com/bar/baz to index.php?q=$1&d=baz Where bar is
I'm trying to rewrite code I've written in matlab in C++ instead. I have
I'm trying to rewrite some query strings I have in my URL like 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.