English 中文(简体)
C#
原标题:Sorting a MatchCollection in C#

我正试图在C#中重新制定《部队派遣国法》。 关注守则如下:

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

在本案中,通过考试程序,我收到一份名单,列出在座标上的所有对应内容,然后,我根据在座标尾的数值,将这份插图清单与另一种表述相加:

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

问题是,如何在C#中实现同样的目标? 我尝试如下:

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

然而,正如我发现的那样,我无法在C#中直接进行相应的收集,因此,我对每一组进行核对:

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

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

然而,当我试图对阵列进行分类时,我看不到可以使用的Sort方法。 我失踪了什么,我是否朝着正确方向前进? 感谢!

最佳回答
问题回答

为了分类阵列,你采用静态<代码>Array.Sort(方法。 尽管如此,为了给你确定一个国际协调委员会所需要的匹配。 或许更方便地做到这一点,是利用小lin子:

var mc = Regex.Matches(input, patter);
var matches = new Match[mc.Count];
mc.CopyTo(matches, 0);
var sorted = matches
    .Select(x => x.Groups[1].Value)
    .OrderBy(x => x);

摊位是按排位顺序排列的第2项物品的价值。 如何运作。 选择会产生你所希望的预测。 秩序混乱。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签