-1
我用C#和新的和我有一些问题。 我正在写一些程序从远程机器下面的输出(使用SSH):解析多行的字符串(C#)
wwn = 5001248018b6d7af
node_wwn = 5001248018b6d7ae
wwn = 5001248118b6d7af
node_wwn = 5001248118b6d7ae
wwn = 5001248218b6d7af
node_wwn = 5001248218b6d7ae
wwn = 5001248318b6d7af
node_wwn = 5001248318b6d7ae
上面的输出保存到字符串...
我需要从这个输出列表或数组中提取以下面的格式:
50:01:24:80:18:B6:D7:AF:50:01:24:80:18:B6:D7:AE
每两行是对( wwn和node_wwn)
我值得下面的函数
public void OutPutParse (string output)
{
string wwnn = null;
string wwpn = null;
string[] test = output.Split('\n');
test = test.Where(item => !string.IsNullOrEmpty(item)).ToArray();
//run all over the test array and exrract the wwns and wwpn
for (int i = 0; i < test.Length; i++)
{
}
}
该功能创建的WWN的阵列(测试)和node_wwn
预期的结果是一个数组或列出将包括WWN + node_wwn这样 50:01 :24:80:18:B6:D7:AF:50:01:24:80:18:B6:D7:AE
看String.split 和 的String.Format 基本上你可以在字符串分割成一个数组。如果需要,可以使用另一个分隔符将数组中的项分开...... 然后,您可以使用string.Format输出。 例如 - var myArray = MyString.Split(':'); String myNewString = String.Format(“{0} {1},myArray [0],myArray [1}”); – AntDC
您能否为问题中的样本输入提供*期望的输出*? –
@DmitryBychenko +1因为xx:xx:xx:yy:yy:yy的列表并没有说太多,似乎很奇怪 – MajkeloDev