gpt4 book ai didi

c# - 对查询字符串 ABC 顺序进行排序(使用 Unix 风格区分大小写的排序顺序),不带分隔符

转载 作者:太空宇宙 更新时间:2023-11-03 14:39:02 25 4
gpt4 key购买 nike

这是我要排序的查询字符串:

string queryString = "Called=%2B12475&ToState=I&CallerCountry=US&Direction=inbound&CallerState=IN&ToZip=&CallSid=CA9fa6986e19f98c3413923a6af1c694&To=%2B128375&CallerZip=&ToCountry=US&ApiVersion=2010-04-01&CalledZip=&CalledCity=&CallStatus=ringing&From=%2B1200582&AccountSid=ACc6d06b4cb61ccbfa61bf1957a5a626&CalledCountry=US&CallerCity=&Caller=%2B2602582&FromCountry=US&ToCity=&FromCity=&CalledState=IN&FromZip=&FromState=IN"

示例结果 = "CallSidCA1234567890ABCDECaller+14158675310Digits1234From+14158675310To+1800555121212345"

我目前拥有的:

string request = "Called=%2B12475&ToState=I&CallerCountry=US&Direction=inbound&CallerState=IN&ToZip=&CallSid=CA9fa6986e19f98c3413923a6af1c694&To=%2B128375&CallerZip=&ToCountry=US&ApiVersion=2010-04-01&CalledZip=&CalledCity=&CallStatus=ringing&From=%2B1200582&AccountSid=ACc6d06b4cb61ccbfa61bf1957a5a626&CalledCountry=US&CallerCity=&Caller=%2B2602582&FromCountry=US&ToCity=&FromCity=&CalledState=IN&FromZip=&FromState=IN"

string[] separator = { "&" };
Int32 testcount = 200;
String[] strlist = request.Split(separator,testcount,StringSplitOptions.RemoveEmptyEntries);
string[] testArray = new string[]
{
"aa",
"ab",
"ac",
"ad",
"ab",
"af"
};

Array.Sort(testArray, StringComparer.InvariantCulture);

执行此操作的最佳方法是什么?

最佳答案

尝试使用 LINQ 拆分字符串,对其进行排序,然后将其放回原处:

string queryString = "Called=%2B12475&ToState=I&CallerCountry=US&Direction=inbound&CallerState=IN&ToZip=&CallSid=CA9fa6986e19f98c3413923a6af1c694&To=%2B128375&CallerZip=&ToCountry=US&ApiVersion=2010-04-01&CalledZip=&CalledCity=&CallStatus=ringing&From=%2B1200582&AccountSid=ACc6d06b4cb61ccbfa61bf1957a5a626&CalledCountry=US&CallerCity=&Caller=%2B2602582&FromCountry=US&ToCity=&FromCity=&CalledState=IN&FromZip=&FromState=IN";

var ordered = queryString.Split('&').OrderBy(x => x).ToList();

var orderedQueryString = string.Join("&", ordered);

这将生成一个与您的查询字符串格式相匹配的字符串。然后,从这里您可以通过执行标准字符串替换来删除定界符:

var noDelim = orderedQueryString.Replace("&", "").Replace("=", "");

我希望这是您的预期输出...根据您提供的问题和样本,目前还不清楚。

关于c# - 对查询字符串 ABC 顺序进行排序(使用 Unix 风格区分大小写的排序顺序),不带分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58417095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com