print number of array elements

x1402

New member
Joined
Sep 7, 2017
Messages
3
Programming Experience
1-3
C#:
        [B]string[] IDS = IDSBox.Text.Split('#');[/B]

        private void Btn_Click(object sender, EventArgs e)
        {
             IDSBox.Text = IDSBox.Text.Replace(IDS[0] + "#"+ IDS[1] + "#" + IDS[2] + "#" + IDS[3] + "#" + IDS[4] + "#" + IDS[5] + "#", "");
        }

i want to print first 100 elements which is stored in IDSBox.Text textbox.
i don't want to put code for every element, is there any method to get elements?
and my code is removing first elements when call Btn_Click event.


example :

IDSBox.Text have 300 array elements which is seprated by #
i want output like this
*1st time click
output : 1#2#3#4#5#........100
*2nd time click
output : 101#102#103#104#105#........200
*3rd time click
output : 201#202#203#204#205#........300

and then again,

*4th time click
output : 1#2#3#4#5#........100
.
.
.
.
*6th time click
output : 201#202#203#204#205#........300
 
I'm not really sure what you are after here, especially with regard to your "multiple click" but this should give you a good idea.

C#:
private void Btn_Click(object sender, EventArgs e)
        {
            string[] IDS = IDSBox.Text.Split('#');
            StringBuilder sb = new StringBuilder();
            int length = (IDS.Length -1) >= 100 ? 100 : IDS.Length - 1;
            for (int i = 0; i < length; i++)
            {
                sb.Append(IDS[i]);
                if (i < length - 1)
                {
                    sb.Append("#");
                }
            }            
            IDSBox.Text = sb.ToString();
        }

If you are saying that you want the "second click" to begin extracting numbers starting at the 101st element then you will need to add a static variable to track that and use that variable in your iteration. Given your examples, the last element in your array will always be empty, hence why the loop uses the length - 1 rather than length.
 
code isnt working for me

i laready said, i want to print number of array elements, then next elements ,,,, to end of array length, . if we reached at array length then again start from first
 
Put your for loop in a function (or method if you prefer) and then call it with two arguments: the first one is the starting index of your loop and the second argument is the ending index for the loop.
 

Latest posts

Back
Top Bottom