Question #58371

I need to write a C# program to read in a text file with following data

Name IPaddress sector department switch port
Randy 192.168.1.25 4 HR 3
Matthew 192.168.1.40 4 HR 15
Hoobert 192.168.2.6 5 CS 4
Reeve 192.168.2.11 5 CS 12
Mary 192.168.4.8 IT 9

and more on the list. and do some modification to the current list like changing the IP segment based on either condition, example base on department CS(customer service)segment has change from 192.168.2.*** to 192.168.16.*** .

secondly am require to add text among all the lines like
"set change mary at 192.168.4.8 from IT port 9 with activation.
1

Expert's answer

2016-03-18T15:48:04-0400
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Question58371
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter file name: ");
            string file = Console.ReadLine();
            Stream fsr = new FileStream(@file + ".txt", FileMode.Open, FileAccess.Read);
            Stream fsw = new FileStream(@file + "_output.txt", FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fsw);
            StreamReader sr = new StreamReader(fsr);
            while (!sr.EndOfStream)
            {
                string temp = sr.ReadLine();
                string name = "";
                int i;
                for (i = 0; i < temp.Length; i++)
                {
                    name += temp[i];
                    if (temp[i] == ' ')
                    {
                        break;
                    }
                }
                string ip = "";
                /*ip.Remove(2);
                ip.Insert(9, "16"); */
                int j;
                for (j = i + 1; j < temp.Length; j++)
                {
                    ip += temp[j];
                    if (temp[j] == ' ')
                    {
                        break;
                    }
                }
                string f = "";
                for (i = j + 1; i < temp.Length; i++)
                {
                    f += temp[i];
                    if (temp[i] == ' ')
                    {
                        break;
                    }
                }
                string port = "";
                for (j = i + 1; j < temp.Length; j++)
                {
                    port += temp[j];
                }
                sw.WriteLine("set change " + name + " at " + ip + " from " + f + "port " + port + " with activation");
            }
            sr.Close();
            sw.Close();
            fsr.Close();
            fsw.Close();
        }
    }
}


http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS