Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Nov 26th, 2005, 7:20 AM   #1
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
array function, error in arrays.

Hey, I'm having trouble with a function, I want it to return all strings that have "Style: " at the beggining, they should return in an array. At first I was having errors because the array wasn't assigned, I assigned a null value but got another error lol. I tried the "ArrayList" too but couldnt get that to return properly. Also in msdn it said IndexOf will return 1 if the string is in, 0 if it is null, but mine returns 0 for all lines with "Style: ", A left() function would probably be better for me with this, as it will always be in the same place, else its invalid, but i couldnt find one . Heres the code:

public string[] setstyles()
        {
            if (textBox1.Text.Length > 1)
            {
                string[] stylearray = null;
                string[] file = textBox1.Text.Split('\n');

                int stylenum = 0;
                
                for (int i = 0; i < file.Length; i++)
                {
                    if (file[i].IndexOf("Style:") >= 0)
                    {
                        // is a style
                        stylearray[stylenum] = file[i]; 
                        
                        stylenum++;
                    }
                    else if ((file[i].IndexOf("Style: ") == 0) && (file[i].IndexOf("Dialogue: ") >= 0))
                    {
                        // styles cant be under dialogue lines, break loop.
                        break;
                    }
                }
                return stylearray;
            }
            else
            {
                return null;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
       textBox1.Text = Convert.ToString(setstyles());
        }

Please help thanks! ~(^O^~)
cloud- is offline   Reply With Quote
Old Nov 26th, 2005, 11:12 AM   #2
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
nvm solved
just used a normal string and split.
cloud- is offline   Reply With Quote
Old Nov 26th, 2005, 11:23 AM   #3
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
In the event that you ever need to use arrays again, you were trying to assgin values to stylearray when it is null. You need to give it a size first, likely based on how much you need to store.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon 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




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

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