我有一个包含随机顺序包含多个值的字符串列表。这些值将以.bat文件的形式写入磁盘,并且必须按照特定的顺序。我想使用.Sort或框架的其他功能,但它没有给我我想要的结果,还尝试了类似LINQ sorting special characters first?的方法,但是还是没有运气。
挑战:
fn main() {
let mut m = "";
foo(42, &mut m);
dbg!(m);
foo(0, &mut m);
dbg!(m);
}
fn foo(n: u64, m: &mut &str) {
if n == 0 {
*m = "asdf";
} else {
*m = "qwerty";
}
}
这给了我输出:
Dim strValues As New List(Of String)
strValues.Add("net use * ""\\ServerName\Folder"" /user:""User"" ""Password""")
strValues.Add("netsh interface ipv4 set address name=""LAN-verbinding"" static 192.168.0.2 255.255.255.0 192.168.0.1")
strValues.Add("""notepad""")
strValues.Add("netsh wlan add profile filename=C:\ConnectPlease.xml user=all")
strValues.Add("netsh wlan add profile filename=C:\Coffee.xml user=all")
strValues.Add("net use * ""\\DifferentServerName\Folder\Subdir"" /user:""User"" ""Password""")
strValues.Sort(Function(x, y)
If Char.IsLetterOrDigit(x(0)) Then
If Not Char.IsLetterOrDigit(y(0)) Then
Return -1
End If
ElseIf Char.IsLetterOrDigit(y(0)) Then
Return 1
End If
Return x.CompareTo(y)
End Function)
Debug.Print(String.Join(vbCrLf, strValues))
这几乎是正确的,除了必须首先使用Netsh命令之外,否则由于未设置网络设置,网络使用不会有任何好处。我想要的结果是:
net use * "\\DifferentServerName\Folder\Subdir" /user:"User" "Password"
net use * "\\ServerName\Folder" /user:"User" "Password"
netsh interface ipv4 set address name="LAN-verbinding" static 192.168.0.152 255.255.255.0 192.168.0.1
netsh wlan add profile filename=C:\Coffee.xml user=all
netsh wlan add profile filename=C:\ConnectPlease.xml user=all
"notepad"
修改 有工作的东西,但是又快又脏,所以如果有人有更好的方法,请告诉我!
netsh interface ipv4 set address name="LAN-verbinding" static 192.168.0.2 255.255.255.0 192.168.0.1
netsh wlan add profile filename=C:\Coffee.xml user=all
netsh wlan add profile filename=C:\ConnectPlease.xml user=all
net use * "\\ServerName\Folder" /user:"User" "Password"
net use * "\\DifferentServerName\Folder\Subdir" /user:"User" "Password"
"notepad"