Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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#_String_List - Fatal编程技术网

C# 获取一个按字母顺序排列的字符串

C# 获取一个按字母顺序排列的字符串,c#,string,list,C#,String,List,这很难说对。基本上,我有一个列表,我需要返回一个字符串,它将是按字母顺序排列的列表中的最后一个。例如: 如果我有名单: { "01", "0a2", "test" } 我需要返回一个按字母顺序排列的字符串,例如“tf”您没有说什么语言 大多数语言都有一个数组排序函数,按字母顺序排序。只需进行排序,然后选择数组的最后一个元素。您不知道使用哪种语言 大多数语言都有一个数组排序函数,按字母顺序排序。只需进行排序,然后选择数组的最后一个元素。这是一个有点粗糙的答案,但我希望这能有所帮助。假设您的字符串

这很难说对。基本上,我有一个列表,我需要返回一个字符串,它将是按字母顺序排列的列表中的最后一个。例如:

如果我有名单:

{ "01", "0a2", "test" }

我需要返回一个按字母顺序排列的字符串,例如“tf”

您没有说什么语言


大多数语言都有一个数组排序函数,按字母顺序排序。只需进行排序,然后选择数组的最后一个元素。

您不知道使用哪种语言


大多数语言都有一个数组排序函数,按字母顺序排序。只需进行排序,然后选择数组的最后一个元素。

这是一个有点粗糙的答案,但我希望这能有所帮助。假设您的字符串在一个排序列表中,我有一个小的“快速脏”方法,该方法按字母顺序生成下一个项目:

var items = new System.Collections.Generic.SortedList<string, string>();

items.Add("01", "01");
items.Add("02a", "02a");
items.Add("test", "test");

var nextItem = items.Last().Key;

int pos = nextItem.Length - 1;
while (pos >= 0)
{
   if ((nextItem[pos] != 'z') && (nextItem[pos] != 'Z'))
   {
      nextItem = nextItem.Substring(0, pos - 1) +  Convert.ToChar(Convert.ToInt32(nextItem[pos]) + 1) + nextItem.Substring(pos + 1);
      break;
    }
    pos--;
 }

 if (pos == -1)
 {
    nextItem += "a";
 }
var items=new System.Collections.Generic.SortedList();
添加(“01”、“01”);
添加(“02a”、“02a”);
添加(“测试”、“测试”);
var nextItem=items.Last().Key;
int pos=nextItem.Length-1;
而(位置>=0)
{
if((nextItem[pos]!='z')&&(nextItem[pos]!='z'))
{
nextItem=nextItem.Substring(0,位置-1)+Convert.ToChar(Convert.ToInt32(nextItem[pos])+1)+nextItem.Substring(位置+1);
打破
}
pos--;
}
如果(位置==-1)
{
nextItem+=“a”;
}

这是一个有点老套的答案,但我希望这能有所帮助。假设您的字符串在一个排序列表中,我有一个小的“快速脏”方法,该方法按字母顺序生成下一个项目:

var items = new System.Collections.Generic.SortedList<string, string>();

items.Add("01", "01");
items.Add("02a", "02a");
items.Add("test", "test");

var nextItem = items.Last().Key;

int pos = nextItem.Length - 1;
while (pos >= 0)
{
   if ((nextItem[pos] != 'z') && (nextItem[pos] != 'Z'))
   {
      nextItem = nextItem.Substring(0, pos - 1) +  Convert.ToChar(Convert.ToInt32(nextItem[pos]) + 1) + nextItem.Substring(pos + 1);
      break;
    }
    pos--;
 }

 if (pos == -1)
 {
    nextItem += "a";
 }
var items=new System.Collections.Generic.SortedList();
添加(“01”、“01”);
添加(“02a”、“02a”);
添加(“测试”、“测试”);
var nextItem=items.Last().Key;
int pos=nextItem.Length-1;
而(位置>=0)
{
if((nextItem[pos]!='z')&&(nextItem[pos]!='z'))
{
nextItem=nextItem.Substring(0,位置-1)+Convert.ToChar(Convert.ToInt32(nextItem[pos])+1)+nextItem.Substring(位置+1);
打破
}
pos--;
}
如果(位置==-1)
{
nextItem+=“a”;
}

如果您总是想要一个在所有现有字符串之后按字母顺序排列为“last”的字符串,那么这应该可以工作;)

var words=new[]{“01”、“0a2”、“test”};
int maxLength=words.ToList().Max(x=>x.Length);
字符串newWord=“”;

对于(int i=0;i如果您总是想要一个在所有现有字符串之后按字母顺序排列为“last”的字符串,这应该可以工作;)

var words=new[]{“01”、“0a2”、“test”};
int maxLength=words.ToList().Max(x=>x.Length);
字符串newWord=“”;

对于(int i=0;iI知道如何排序,但我需要创建一个按字母顺序排列比数组中的字符串大的新字符串…我知道如何排序,但我需要创建一个按字母顺序排列比数组中的字符串大的新字符串…您想要字母顺序高于“测试”的
字符串吗?
若要将字符转换为字符并将其添加到字符码中,则“test”将位于“tf”之前。您希望字母顺序高于“test”
?能否将它们转换为字符并将其添加到字符码中,“test”将位于“tf”之前。有趣的答案。让我试试:)我有一个小问题。它的结果是:-它开始时很好,然后一次又一次地做同样的事情。有什么想法吗?有趣的答案。让我试试:)我有一个小问题。。这就是它最终的结果:-它开始做得很好,然后一次又一次地做同样的事情。有什么想法吗?“test”后面的单词按字母顺序是“tesu”而不是“testz”。在“test”后面的单词按字母顺序是“tesu”而不是“testz”。