suppose we have 2 textbox.
in textbox1 there is name and in textbox2 mobile no.
and output is combination of these 2.
ex..
textbox1.....josop
textbox2.....9970345678
output...
j9o9s7o03p45678
thank you.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
shashank kalePosted Nov 8, 2008, 12:45 PM
Satish KathiPosted Nov 7, 2008, 2:44 PM
StringBuilder r = new StringBuilder();
int i;
for (i = 0; i < textBox1.Text.Length; i++)
{
r.Append(textBox1.Text.Substring(i, 1));
if (textBox2.Text.Length > i)
{
r.Append(textBox2.Text.Substring(i, 1));
}
}
if (textBox2.Text.Length > i)
r.Append(textBox2.Text.Substring(i));
label2.Text = r.ToString();
AlanPosted Nov 7, 2008, 2:19 PM
You can do this (rather messily) with code such as this:
string text1 = textBox1.Text; // "josop"
string text2 = textBox2.Text; // "9970345678"
char[] chars = new char[text1.Length + text2.Length];
chars[0] = text1[0];
chars[1] = text2[0];
chars[2] = text1[1];
chars[3] = text2[1];
chars[4] = text1[2];
chars[5] = text2[2];
chars[6] = text1[3];
chars[7] = text2[3];
chars[8] = text2[4]; // is this the right way around?
chars[9] = text1[4]; // ditto
for(int i = 10; i < chars.Length; i++)
{
chars[i] = text2[i - 5];
}
string output = new string(chars);
string message = String.Format("The combination of '{0}' and '{1}' is '{2}'", text1, text2, output);
MessageBox.Show(message);
However, if you want to do this generally, you'll need to be clear on how many elements of each string are to be interleaved.