![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4
![]() |
Reading files, comparing strings
I am reading in a textfile and have to check weather the lines start with a certain character. I have tried string.StartsWith() and converting the string to an array of chars, but it still didn't work.
Here is the code private bool LoadList(string path)
{
BlockedApps = new ArrayList();
Allowed = new ArrayList();
StreamReader file;
string line;
try
{
file = new StreamReader(path);
line = file.ReadLine();
while (line != null)
{
System.Windows.Forms.MessageBox.Show(line);
if (line.StartsWith("-"))
{
string temp = line.Substring(1, line.Length).ToUpper();
Allowed.Add(temp);
}
else
{
BlockedApps.Add(line.ToUpper());
}
line = file.ReadLine();
}
file.Close();
}
catch (Exception)
{
return false;
}
return true;
} |
|
|
|
|
|
#2 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3
![]() |
I think you can access the string as an array, for example:
string s = "hello world"; char c = s[0];
__________________
Quote:
|
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
if (line[0] == "-")
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4
![]() |
Thanks guys. It works now
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comparing same table from 2 different .mdb files | Roger | Visual Basic | 1 | Jun 28th, 2005 5:46 PM |
| Reading Excel files on the web | sagi | Other Web Development Languages | 3 | May 2nd, 2005 11:24 AM |
| Reading Files, and Formating | brokenhope | C++ | 6 | Apr 18th, 2005 5:01 PM |
| Comparing strings.... | balltheheed | Java | 3 | Apr 8th, 2005 4:26 AM |
| shutil.copy corrupting files? | TimL | Python | 0 | Feb 20th, 2005 4:32 PM |