-1

I new with C# and in and I have some questions. I'm writing some program that get the following output from remote machine (using SSH):

wwn = 5001248018b6d7af

node_wwn = 5001248018b6d7ae

wwn = 5001248118b6d7af

node_wwn = 5001248118b6d7ae

wwn = 5001248218b6d7af

node_wwn = 5001248218b6d7ae

wwn = 5001248318b6d7af

node_wwn = 5001248318b6d7ae     

The output above save into string...

I need to extract from this output List or Array in the following format:

50:01:24:80:18:b6:d7:af:50:01:24:80:18:b6:d7:ae

each two lines are couple (wwn and node_wwn)

I worth the following function

    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++)
        {

        }


    }

this function create an array (test) of wwns and node_wwn

the expected results is an array or list the will include wwn + node_wwn like this 50:01:24:80:18:b6:d7:af:50:01:24:80:18:b6:d7:ae

almog50
  • 75
  • 1
  • 8
  • 1
    Look at String.split and String.Format Basically you can split that string into an array. You could then split the items in the array if needed with another delimiter.... You could then use string.Format to output. eg - var myArray = MyString.Split(':'); String myNewString = String.Format("{0}{1}, myArray[0], myArray[1}"); – AntDC Nov 17 '15 at 11:31
  • 1
    Could you, please, provide the *desired output* for the sample input in the question? – Dmitry Bychenko Nov 17 '15 at 11:31
  • @DmitryBychenko +1 because List of xx:xx:xx:yy:yy:yy doesn't say to much it seems strange – MajkeloDev Nov 17 '15 at 11:33
  • Have you tried anything yet? This is fairly simple but I'm reluctant to give you code for free... – DavidG Nov 17 '15 at 11:50
  • I edited the question with some new useful info I hope – almog50 Nov 17 '15 at 19:25

1 Answers1

0

The easiest way to achieve this is:

string www = "5001248018b6d7af";
string wwwn = "5001248018b6d7ae";

string myString = "";

// Implemenet loop here.
// www = "number" // the next number you get
// wwwn = "number" // the next number you get
myString = www + myString + wwwn;

You just have to do it with a loop when you have a list of strings or something.

If you want to have it in the same order you can either do it with a character between the strings like a ";" and split all numbers or you just do two strings and combine them at the end like that:

string www = "5001248018b6d7af";
string wwwn = "5001248018b6d7ae";
string mywwwString = "";
string mywwwnString = "";

// Implement the loop to add strings here
// www = "number" // the next number you get
// wwwn = "number" // the next number you get
mywwwString += www;
mywwwnString += wwwn;
string myString = www  + wwwn;
FKutsche
  • 392
  • 2
  • 17