سؤال

I have about about 30 buttons each contain text and then a number and i just need to put the number in the other button

like in the example button1.Name should be test3

Is this possible?

i know that LastIndexOf doesnt work like this, it's for giving the idea what i want to adchieve

button1 = "hello1"; //this varies in normal program
button2 = "notimportant3"; //this varies in normal program

button1.Name = "test"+button2.Name.LastIndexOf(1);
هل كانت مفيدة؟

المحلول

button1.Name = "test" + button2.Name[button2.Name.Length-1];

or better use string.Format() to format the string

like

button1.Name  = string.Format("test{0}", button2.Name[button2.Name.Length-1]);

نصائح أخرى

button1.Name  = string.Format("test{0}", button2.Name[button2.Name.Length - 1]);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top