Question
This is the given code : using System; using System.Net; using System.IO; using System.Text; class PropertyManager { public static void Main() { // put your
This is the given code :
using System; using System.Net; using System.IO; using System.Text;
class PropertyManager { public static void Main() { // put your computer's location here string logFile = "LOGFILE.TXT"; FileStream fs1 = new FileStream(logFile, FileMode.Open, FileAccess.Read);
// put your computer's location here string outputfile = "OUTPUT.TXT"; FileStream fs2 = new FileStream(outputfile, FileMode.Create, FileAccess.Write); StringBuilder sb = new StringBuilder();
StreamReader sr = new StreamReader(fs1); StreamWriter sw = new StreamWriter(fs2);
while (sr.Peek() > -1) { sb.Append(sr.ReadLine()); }
String input = sb.ToString();
char[] h = { ',', '*', '/' }; String[] p; p = input.Split(h);
int temp = 0; for (int i = 0; i
Console.WriteLine("*********************"); Console.WriteLine("The ip address is {0}", p[temp]); sw.WriteLine("*********************", p[temp]); sw.WriteLine("The ip address is {0}", p[temp]);
sw.Close(); sr.Close(); fs1.Close(); fs2.Close(); } }
Question 1. (50 Points) You will write a program that will read a text file, process it, find the ipv4 number in the package and write it to another text file. LOGFILE.TXT and SamleOUTPUT.TXT" files are given to you. The output of this program or your answer shall be the same as the contents of SamleOUTPUT.TXT. Please follow these steps: a. Use the given LOGFILE.TXT" i. Open the file in your code using FileStream and StreamReader Classes, ii. As we discussed in the class, StringBuilder Class is designed to store strings effectively and fast so, 1. Create a StringBuilder Object 2. Read everything from the file and store in this object using the Append Method of this object inside a while loop. b. StringBuilder Objects are good at storing effectively but not good at string operations. For example, they don't have Split method that comes with string Class. i. So copy StringBuilder's data to a simple string object, e.x. ( String input = sb.ToString();) c. Create a char array such as (char[] h = {';', '*','/'};) , these are the list of delimiter that will be used to parse the file. d. Create a string array to store the result of parsing. ( String[] p; ) e. Do the parsing (p = input. Split(h); ) f. Write a for loop that will check every element in array p and find the ones with the ".'s in them. i. For each, you can use Indexof method such as if(p[i]. IndexOf('') !=-1) this means that there is . in the element. ii. But some elements have dots but not numbers iii. Parse again using as the delimiter. iv. Check each parsed element whether it is a number andStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started