Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何对列表进行排序<;字符串>;当数字是字符串的一部分时,按从低到高的数字排列?_C#_.net_Winforms - Fatal编程技术网

C# 如何对列表进行排序<;字符串>;当数字是字符串的一部分时,按从低到高的数字排列?

C# 如何对列表进行排序<;字符串>;当数字是字符串的一部分时,按从低到高的数字排列?,c#,.net,winforms,C#,.net,Winforms,我有一个列表,例如,在本例中,第一个索引是: "07:53 אזעקה באשדוד, ביתר עילית, גן יבנה, מעלה אדומים, קריית מלאכי ובמ״א באר" 这是一个标题,它是一个字符串,但我认为它是一个标题。 索引是:“1.你好” 索引2是:“5.你好,世界” 以此类推,例如索引7是:“66.大家好” 问题是在索引7中我有“66”。 在索引2“5中。 在索引9中,我有“3” 后面带点的数字是字符串的一部分,但我仍然希望根据字符串中的数字对列表进行排

我有一个列表,例如,在本例中,第一个索引是:

"07:53 אזעקה באשדוד, ביתר עילית, גן יבנה, מעלה אדומים, קריית מלאכי ובמ״א באר"

这是一个标题,它是一个字符串,但我认为它是一个标题。 索引是:“1.你好” 索引2是:“5.你好,世界”

以此类推,例如索引7是:“66.大家好”

问题是在索引7中我有“66”。 在索引2“5中。 在索引9中,我有“3”

后面带点的数字是字符串的一部分,但我仍然希望根据字符串中的数字对列表进行排序

这就是我每次创建列表的方式

public List<string> GetResponsers(string contents)
{
    string responser = "";
    List<string> threadList = new List<string>();
    int f = 0;
    int startPos = 0;
    while (true)
    {
        string firstTag = "<FONT CLASS='text16b'>";
        string lastTag = "&n";
        f = contents.IndexOf(firstTag, startPos);
        if (f == -1)
        {
            break;
        }
        int g = contents.IndexOf(lastTag, f);
        startPos = g + lastTag.Length;
        responser = contents.Substring(f + 22, g - f - 22);
        threadList.Add(responser);
    }
    SortList(threadList);
    return threadList;
}
public List getresponser(字符串内容)
{
字符串应答器=”;
List threadList=新列表();
int f=0;
int startPos=0;
while(true)
{
字符串firstTag=“”;
字符串lastTag=“&n”;
f=contents.IndexOf(firstTag,startPos);
如果(f==-1)
{
打破
}
int g=contents.IndexOf(lastTag,f);
startPos=g+lastTag.Length;
应答器=内容。子串(f+22,g-f-22);
线程列表。添加(响应者);
}
SortList(线程列表);
返回线程列表;
}
我是这样分类的:

public List<string> SortList(List<string> thread)
{
    thread = thread
        .OrderBy(str =>
         {
             var match = Regex.Match(str, @"^([-+]?\d+)");
             return match.Success ? int.Parse(match.Groups[1].Value) : int.MaxValue;
         })
         .ToList();
    responsers.Add(new List<string>(thread));
    return thread;
}
公共列表排序列表(列表线程)
{
线程=线程
.OrderBy(str=>
{
var match=Regex.match(str,@“^([-+])?\d+);
返回match.Success?int.Parse(match.Groups[1].Value):int.MaxValue;
})
.ToList();
添加(新列表(线程));
返回线程;
}
例如,在列表中,作为标题的第一个索引(索引0)如下所示:

这是一个索引0:07:07:07:07:53的本方索引索引0:07:07:53的本方索引的本方索引的本方索引的本方索引的本方索引的本方索引的本方索引的本方索引的本方索引的本方索引的本方索引的本方索引的本方索引的本方索引,本方是本方索引的本方索引的本方,本方是本方,本方,本方是本方,本方,本方是本方,本方,本方,本方,本方是本方,本方,本方,本方,本方,本方是本方,本方,本方若若若若若本方在本方,本方,本方在本方的本方的本方的本方,本方,本方,本方,本方,本方若若若若若本方的本方在本方的本方的本方的本方的本方的本方的本方的本本方的本1497•במאבאר 这个不应该按数字排序,但因为它的末尾有一个数字:07:53,它将对它进行排序并将其放入索引7中 自从2007年以来

或者如果我在索引0中有另一个列表:07:48 同样,因为07,它将把这个索引0放在索引7上

但我需要在任何情况下,索引0都将是最后一个索引

SortList方法正在发挥作用,但在类似07:48אזעקהמ״אמבבים的情况下,它将把它放在索引07中,而不仅仅放在最后一个索引中。07:48不应该是其他数字1.2.3.4.5.6的一部分

字符串中的数字总是这样开头:“1。 数字、点、空间

"二,。 “55


但是07:43不是一个应该与其他数字一起排序的数字。

创建一个新的类来存储当前创建的字符串列表和要排序的数值。然后更改排序方法,只使用新类中的数字字段。

检查索引号后的点(
)是否足够

public List<string> SortList(List<string> thread)
{
    thread = thread
        .OrderBy(str =>
        {
            var match = Regex.Match(str, @"^([-+]?\d+)\.");
            return match.Success ? int.Parse(match.Groups[1].Value) : int.MaxValue;
        })
        .ToList();
    responsers.Add(thread); // was: responsers.Add(new List<string>(thread));
    return thread;
}
公共列表排序列表(列表线程)
{
线程=线程
.OrderBy(str=>
{
var match=Regex.match(str,@“^([-+])?\d+\”;
返回match.Success?int.Parse(match.Groups[1].Value):int.MaxValue;
})
.ToList();
responsers.Add(线程);//was:responsers.Add(新列表(线程));
返回线程;
}