Hello,

I have in one textbox this values separated by comma:
2,4,5,6,7,8,9,0,2,0,2,3,4,5,1,2,3,4

In a new textbox I want only some portion of this vector, from the 7th position to the 15th.
9,0,2,0,2,3,4,5,1

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.

Hi,

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.

Thanks.

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.

Perfect! Thanks a lot! :)

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.

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)
               test+=delimiter;     
       textBox2.Text = test;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.