Ich möchte einen bestimmten Teil einer Ausgabezeichenfolge (der Servername) nehmen. Es funktioniert, aber ich gebe mehr Zeichen zurück, als ich brauche, und ich möchte nur den Servernamen.Wie Teil einer Zeichenfolge ohne Verwendung von Teilzeichenfolge
Mein Code:
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c nslookup -type=mx gmail.com"; // Note the /c command (*)
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
//* Read the output (or the error)
string output = process.StandardOutput.ReadToEnd();
MessageBox.Show(output);
string[] tokens = output.Split(' ');
//take my server name
string retVal = tokens[11];
MessageBox.Show(retVal);
Meine Ausgabe String:
Servidor: UnKnown
Address: 192.168.0.1
Não é resposta autoritativa:
hotmail.com MX preference = 5, mail exchanger = mx3.hotmail.com//I WANT THIS STRING "mx3.hotmail.com", the first name server
hotmail.com MX preference = 5, mail exchanger = mx4.hotmail.com
hotmail.com MX preference = 5, mail exchanger = mx1.hotmail.com
hotmail.com MX preference = 5, mail exchanger = mx2.hotmail.com
mx4.hotmail.com internet address = 207.46.8.167
mx4.hotmail.com internet address = 65.54.188.126
mx4.hotmail.com internet address = 65.54.188.110
mx4.hotmail.com internet address = 65.54.188.94
mx4.hotmail.com internet address = 65.55.37.104
mx4.hotmail.com internet address = 65.55.92.184
mx4.hotmail.com internet address = 65.55.92.168
mx4.hotmail.com internet address = 65.55.33.119
mx4.hotmail.com internet address = 207.46.8.199
...
meine retVal (Variablenname):
mx3.hotmail.com hotmail MX
Ich will nur "mx3.hotmail.com"
PS: retVal.Substring (0, 14); funktionieren nicht für mich, weil der Servername lengths variiert.
danke! = D
retVal.Split (‘‚) [0] – serhiyb
zurückgeben "=" –
auf der Grundlage Ihrer Frage retVal enthält „mx3.h otmail.com hotmail MX "und offensichtlich gibt es keine Möglichkeit, es zurückzukehren" = " – serhiyb