String Array

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

String Array

 
0
  #1
Jan 19th, 2009
Is there any method to find the number of elements that are filled in an array

lets say i have the following array defined

string[] text = new string[50]

and i fill the first 8 elements/indexes

Is there any method that could return the number of elements/indexes within an string array that are filled?

I tried using text.lenght() but that returns the total size of array. In above case it would return 50 which is not what i want...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: String Array

 
0
  #2
Jan 19th, 2009
Hello, gallian99.
I haven't heard about such standard functions I can offer two alternative ways for you:
1. Using reference types (like ArrayList). You'll able to add elements dynamically and get the actual size of your array.
2. Create your own structure/class, that will contain your array, the full array size (in your case it's 50) and number of added elements.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: String Array

 
0
  #3
Jan 19th, 2009
Thanks Anteka,

I have tackled it using an alternate already. But I should better try ArrayList as well. Haven't work around with it yet

Originally Posted by Antenka View Post
Hello, gallian99.
I haven't heard about such standard functions I can offer two alternative ways for you:
1. Using reference types (like ArrayList). You'll able to add elements dynamically and get the actual size of your array.
2. Create your own structure/class, that will contain your array, the full array size (in your case it's 50) and number of added elements.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,605
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: String Array

 
0
  #4
Jan 19th, 2009
If you are running on .NET 3, you can use Lists, which are very easy:

  1. List<String> strings = new List<String>(); //initialise the list
  2. strings.Add(str); //Add an item
  3. int length = strings.Count; //how many strings are in the list.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

Re: String Array

 
0
  #5
Jan 19th, 2009
hi
u can do this

  1. int counter=0; // global value
  2. while(true)
  3. {
  4.  
  5. if (s[counter] != null)
  6. {
  7. comboBox1.Items.Add(s[counter]);
  8. counter++;
  9. }
  10. else
  11. {
  12. break;
  13. }
  14. }

bye
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: String Array

 
0
  #6
Jan 19th, 2009
You should follow scru's advice and use a List<T> if you want to have a resizable container.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,927
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 276
ddanbe's Avatar
ddanbe ddanbe is online now Online
Posting Virtuoso

Re: String Array

 
0
  #7
Jan 21st, 2009
An ArrayList is also resizable, still usable but a bit "out of date".
If I where you follow the advise off scru and Rashakil Fol.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: String Array

 
0
  #8
Jan 21st, 2009
Thanks!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: String Array

 
0
  #9
Jan 22nd, 2009
try this ??? is easy way to find

  1. int I = 0;
  2. foreach (string S in Text)
  3. {
  4. int I += 1;
  5. }
  6. Console.WriteLine(I.ToString());
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: String Array

 
0
  #10
Jan 22nd, 2009
Originally Posted by cVz View Post
try this ??? is easy way to find
Well this is about the dumbest reply I've read on this forum. Did you even read the question?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC