I have in one textbox this values separated by comma:

In a new textbox I want only some portion of this vector, from the 7th position to the 15th.

How can I do this?

Best regards!

newtextbox.Text = oldtextbox.Text.Substring(12);

The 12 accounts for the commas in the string. Substring(12) grabs all characters (including) 12 and beyond.


But i need a some interval, substring give me from some position the end.

I want from X to Y in a list of numbers.


It has a variant Substring(startindex, length) . If you're going to do it based on index of the number alone you could copy it into a new string without the commas.

Use the Split method:

string text = "1,3,5,3,7,9,4,6,1,3";
            string[] numbers = text.Split(',');
            string test = numbers[2];

In this case, the string test will contain "5". That way you can manipulate everything to your liking.

Edited 6 Years Ago by ddanbe: n/a

Just today I have try this code and I still have the problem:
If I try the lasted solution in this case:

textBox1.Text= "1.2,2,3.2,4,5,6,7,8";

string text = textBox1.Text;
           string[] numbers = text.Split(',');
           string test = numbers[0];
           textBox2.Text = test1;

I only have a single number. I want a range between Xposition to other Xposition on a big range of numbers.

Eg. I want a string with 3.2,4,5 from the example 1.2,2,3.2,4,5,6,7,8, the range start from position 2 to 4.

If I use the substring solution substring alone the "." is considered a value...

thanks a lot.

Edited 6 Years Ago by chromatinpt: n/a

string text = textBox1.Text;
string[] numbers = text.Split(',');
string delimiter = ","; //or leave out the , and put a space
string test = "";
for(int i = start;i<=end;i++) //to include the right endpoint
       test += numbers[i];  //or you can parse your numbers into ints
       if (i !=end)
       textBox2.Text = test;

Edited 6 Years Ago by jonsca: n/a

This question has already been answered. Start a new discussion instead.