I got a file with lots of ASCII characters. No extension, and has the Type Of file attribute 190000 File.
I have many characters like L¿ö in the file however I required to remove lines from a word PYGR to another word MCG. It has several lines in between.
I tried the following code. And got everything working. Indexes are 3 and 19001 respectively,
VB:
Dim Load_File = System.IO.File.ReadAllText("C:\Documents and Settings\Fousu.s\Desktop\Files\SYSI091512.190000")
Dim EditedString = ""
Dim IndexofPYGR = Load_File.IndexOf("PYGR")
Dim indexOfMCG = Load_File.LastIndexOf("MCG")
Dim LengthMCG = "MCG"
'System.Console.ReadKey()
If ((IndexofPYGR > -1) And (indexOfMCG > -1)) Then
EditedString = Load_File.Remove(IndexofPYGR, (indexOfMCG - (LengthMCG.Length + 1)))
System.IO.File.WriteAllText("C:\Documents and Settings\Fousu.s\Desktop\Files\SYSI091512.190000V1", EditedString)
End If
c#
//Getting the file as a string.
string Load_File = System.IO.File.ReadAllText(@"C:\Documents and Settings\Fousu.s\Desktop\Files\SYSI091512.190000");
string EditedString;
int IndexofPYGR = Load_File.IndexOf("PYGR");
int indexOfMCG = Load_File.IndexOf("MCG");
string LengthMCG = "MCG";
//Console.WriteLine("Index of PYGR is : {0}", IndexofPYGR);
//Console.WriteLine("Index of MCG is : {0}", indexOfMCG);
//System.Console.ReadKey();
if ((IndexofPYGR != -1) && (indexOfMCG != -1))
{
EditedString = Load_File.Remove(IndexofPYGR, (indexOfMCG - (LengthMCG.Length + 1)));
System.IO.File.WriteAllText(@"C:\Documents and Settings\Fousu.s\Desktop\Files\SYSI091512.190000V1", EditedString);
Would like to request a review of the above code, or is there a better way to achieve this? and also would like to know how to get the Type Of File attribute to 190000.