Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 4th, 2007, 2:42 AM   #1
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4 Wizard1988 is on a distinguished road
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;
        }
I hope this isn't one of those stupid mistakes.....
__________________

Wizard1988 is offline   Reply With Quote
Old Jul 4th, 2007, 4:51 AM   #2
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
I think you can access the string as an array, for example:
string s = "hello world";
char c =  s[0];
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jul 5th, 2007, 11:04 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
if (line[0] == "-")
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jul 5th, 2007, 5:10 PM   #4
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4 Wizard1988 is on a distinguished road
Thanks guys. It works now
__________________

Wizard1988 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:51 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC