Click here to Skip to main content
15,885,782 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
Richard Deeming1-Apr-22 0:51
mveRichard Deeming1-Apr-22 0:51 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
OriginalGriff1-Apr-22 0:53
mveOriginalGriff1-Apr-22 0:53 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
Richard MacCutchan1-Apr-22 1:07
mveRichard MacCutchan1-Apr-22 1:07 
GeneralRe: C# Exception: An object reference does not point to an instance of an objec Pin
Dave Kreskowiak1-Apr-22 2:12
mveDave Kreskowiak1-Apr-22 2:12 
GeneralRe: C# Exception: An object reference does not point to an instance of an objec Pin
Gary R. Wheeler2-Apr-22 3:21
Gary R. Wheeler2-Apr-22 3:21 
GeneralRe: C# Exception: An object reference does not point to an instance of an objec Pin
Pete O'Hanlon5-Apr-22 4:03
mvePete O'Hanlon5-Apr-22 4:03 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
Raphael Adeniji10-Apr-22 14:20
Raphael Adeniji10-Apr-22 14:20 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
Raphael Adeniji12-Apr-22 3:36
Raphael Adeniji12-Apr-22 3:36 
//Try this procedure and manipulate it

public void RewriteFile(string SourceFileFullName, string TargetFileFullName, string UnWantedFilterString = "")
{
//UnWantedFilterString variable allows a line to be eliminated in the target file if it is contained in the line, this can be fine-tuned depending on your need.
//SourceFileFullName and TargetFileFullName should be full file path and name

if (!File.Exists(SourceFileFullName))
{
MessageBox.Show("Source File Does Not Exist, Confirm on the Disk.");
return;
}

string CurrentLine = "";
string CurrentLineTrimedUcase = "";

string UnWantedFilterUpperTrimed = UnWantedFilterString.Trim().ToUpper(); //This is string of anything you do not want to eliminate a line

try
{
StringBuilder sb2 = new StringBuilder("");

using (StreamReader sr = File.OpenText(SourceFileFullName))
{
while ((CurrentLine = sr.ReadLine()) != null)
{

CurrentLineTrimedUcase = CurrentLine.Trim().ToUpper().Replace("\t", ""); //Avoid tabs, trim and change to upper case


if (UnWantedFilterUpperTrimed == "") //Test for unwated Filter string
{
sb2.AppendLine(CurrentLine); // Append line string to StringBuilder if unwanted filter empty

}
else
{
if (CurrentLineTrimedUcase.IndexOf(UnWantedFilterUpperTrimed) < 0)
{
sb2.AppendLine(CurrentLine); // Only Append line string to StringBuilder if unwanted filter not in string
}
}

}
}

if (sb2.Length == 0)//Empty file will not be written
{
MessageBox.Show("Empty File will not be re-written");
return;
}

//Delete target file if it exists
if (File.Exists(TargetFileFullName))
{
File.Delete(TargetFileFullName);
}
//Write file now
using (StreamWriter sw = File.CreateText(TargetFileFullName))
{

sw.Write(sb2);
}

MessageBox.Show("File Written Successfully");
return;

}
catch(Exception ex)
{

MessageBox.Show(ex.Message + " --- File Not Written");

}


}
QuestionAccess Android Tablet from C# Pin
Kevin Marois30-Mar-22 18:23
professionalKevin Marois30-Mar-22 18:23 
AnswerRe: Access Android Tablet from C# Pin
Richard MacCutchan30-Mar-22 22:30
mveRichard MacCutchan30-Mar-22 22:30 
GeneralRe: Access Android Tablet from C# Pin
Kevin Marois31-Mar-22 6:15
professionalKevin Marois31-Mar-22 6:15 
GeneralRe: Access Android Tablet from C# Pin
Richard MacCutchan31-Mar-22 6:19
mveRichard MacCutchan31-Mar-22 6:19 
AnswerRe: Access Android Tablet from C# Pin
OriginalGriff31-Mar-22 3:09
mveOriginalGriff31-Mar-22 3:09 
GeneralRe: Access Android Tablet from C# Pin
Kevin Marois31-Mar-22 6:16
professionalKevin Marois31-Mar-22 6:16 
GeneralRe: Access Android Tablet from C# Pin
Kevin Marois31-Mar-22 8:11
professionalKevin Marois31-Mar-22 8:11 
GeneralRe: Access Android Tablet from C# Pin
OriginalGriff31-Mar-22 19:49
mveOriginalGriff31-Mar-22 19:49 
QuestionError when parsing string as int Pin
Member 1558328029-Mar-22 5:19
Member 1558328029-Mar-22 5:19 
AnswerRe: Error when parsing string as int Pin
Dave Kreskowiak29-Mar-22 5:33
mveDave Kreskowiak29-Mar-22 5:33 
QuestionFind the smallest integer that is not in a random array Pin
Member 1204230226-Mar-22 8:01
Member 1204230226-Mar-22 8:01 
AnswerRe: Find the smallest integer that is not in a random array Pin
OriginalGriff26-Mar-22 8:22
mveOriginalGriff26-Mar-22 8:22 
GeneralRe: Find the smallest integer that is not in a random array Pin
Member 1204230226-Mar-22 8:29
Member 1204230226-Mar-22 8:29 
GeneralRe: Find the smallest integer that is not in a random array Pin
OriginalGriff26-Mar-22 8:46
mveOriginalGriff26-Mar-22 8:46 
GeneralRe: Find the smallest integer that is not in a random array Pin
Member 1204230226-Mar-22 9:51
Member 1204230226-Mar-22 9:51 
GeneralRe: Find the smallest integer that is not in a random array Pin
OriginalGriff26-Mar-22 11:43
mveOriginalGriff26-Mar-22 11:43 
GeneralRe: Find the smallest integer that is not in a random array Pin
Member 1204230226-Mar-22 12:17
Member 1204230226-Mar-22 12:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.