Shoutbox

c# Read text file - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: c# Read text file (/showthread.php?tid=92495)

c# Read text file by djdannyp on 10-07-2009 at 02:34 PM

Okay, here's the situation:

In a C# program I need to read back a text file (from a fixed location) and check that the last character on the second to last line is a 0 and then return true or false.

It sounds so simple (and probably is for someone with semi-decent coding knowledge!), but I'm really struggling with how to accomplish it

Can anyone help me out?

Thanks :)



Also, if anyone knows how to Enable Windows Defender via C# that'd be a MASSIVE help too!

Thanks again :)


RE: c# Read text file by Mnjul on 10-07-2009 at 04:59 PM

You could use File.ReadAllLines to read the contents of the file to an array of string, each element a line, and access the last char of the second-to-last line using lines[lines.Length-2][lines[lines.Length-2].Length-1] (a bit messy, hope you figure it out :P)


RE: c# Read text file by Ezra on 10-07-2009 at 09:35 PM

What he said but in code ;)

C# code:
String[] lines = File.ReadAllLines("C:\\thepath.txt");
Char thing = lines[lines.Length - 2][lines[lines.Length - 2].Length - 1];


RE: c# Read text file by djdannyp on 10-08-2009 at 12:37 AM

Thanks, yeah, I'd just about managed to put it into code and get it working :)

If anyone can shed any light on the Windows Defender situation that'd also be much appreciated!