Zum Inhalt springen

inteldenim

Mitglieder
  • Gesamte Inhalte

    4
  • Benutzer seit

  • Letzter Besuch

Reputationsaktivitäten

  1. Positiv
    inteldenim hat eine Reaktion von Gurki erhalten in Knobelaufgabe SED   
    Hallo, ungetestet.
     
    public void AppendHostnamesToHostsFile(string filePath) { string[] lines = File.ReadAllLines(filePath); List<string> updatedLines = new List<string>(); foreach (string line in lines) { if (!string.IsNullOrWhiteSpace(line) && !line.Contains('#')) // Leere Zeilen, Kommentare skippen { var parts = line.Split(' '); if (parts.Length == 2 && parts[1].Contains(".")) { string ip = parts[0]; string fullName = parts[1]; // FQDN string shortName = fullName.Split('.')[0]; // Hostname updatedLines.Add($"{ip} {fullName} {shortName}"); } else { updatedLines.Add(line); //Sonstige Zeilen unverändert } } } File.WriteAllLines(filePath, updatedLines.ToArray()); }

     
     
  2. Positiv
    inteldenim hat eine Reaktion von Dr. Octagon erhalten in Knobelaufgabe SED   
    Hallo, ungetestet.
     
    public void AppendHostnamesToHostsFile(string filePath) { string[] lines = File.ReadAllLines(filePath); List<string> updatedLines = new List<string>(); foreach (string line in lines) { if (!string.IsNullOrWhiteSpace(line) && !line.Contains('#')) // Leere Zeilen, Kommentare skippen { var parts = line.Split(' '); if (parts.Length == 2 && parts[1].Contains(".")) { string ip = parts[0]; string fullName = parts[1]; // FQDN string shortName = fullName.Split('.')[0]; // Hostname updatedLines.Add($"{ip} {fullName} {shortName}"); } else { updatedLines.Add(line); //Sonstige Zeilen unverändert } } } File.WriteAllLines(filePath, updatedLines.ToArray()); }

     
     

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...