String.Insert Doesn't work...

  • Thread starter Nicholas Paldino [.NET/C# MVP]
  • Start date
N

Nicholas Paldino [.NET/C# MVP]

Steph,

The Insert method does not change the string it is called on. Strings
are immutable. Rather, it returns a new string that has the inserted text.
All methods that perform operations on strings work in this manner.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

String.Insert doesn't seems to work.... (see example below)
Could someone explain me this ? :
private void button1_Click(object sender, System.EventArgs e)
{
string tmp="12345678901234567890";
string toinsert="HELLO";
tmp.Insert(10,toinsert);
MessageBox.Show(tmp);
}
And the message box show : 12345678901234567890 instead of
1234567890HELLO1234567890
Thanks for Help,

steph.
 
S

Steph.

Hi,

String.Insert doesn't seems to work.... (see example below)
Could someone explain me this ? :
private void button1_Click(object sender, System.EventArgs e)
{
string tmp="12345678901234567890";
string toinsert="HELLO";
tmp.Insert(10,toinsert);
MessageBox.Show(tmp);
}

And the message box show : 12345678901234567890 instead of 1234567890HELLO1234567890

Thanks for Help,



steph.
 
J

John J. Hughes II

try MessageBox.Show(tmp.Insert(10,toinsert));

regards,
John

Hi,

String.Insert doesn't seems to work.... (see example below)
Could someone explain me this ? :
private void button1_Click(object sender, System.EventArgs e)
{
string tmp="12345678901234567890";
string toinsert="HELLO";
tmp.Insert(10,toinsert);
MessageBox.Show(tmp);
}
And the message box show : 12345678901234567890 instead of
1234567890HELLO1234567890
Thanks for Help,

steph.
 
P

Peter Jausovec

Hi,

Try this:


string tmp = "12345678901234567890";
string toInsert = "HELLO";
tmp = tmp.Insert (10, toInsert);

Regards,
Peter Jausovec
(http://blog.jausovec.net)


Hi,

String.Insert doesn't seems to work.... (see example below)
Could someone explain me this ? :
private void button1_Click(object sender, System.EventArgs e)
{
string tmp="12345678901234567890";
string toinsert="HELLO";
tmp.Insert(10,toinsert);
MessageBox.Show(tmp);
}

And the message box show : 12345678901234567890 instead of 1234567890HELLO1234567890

Thanks for Help,



steph.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top