Link to home
Start Free TrialLog in
Avatar of samliam
samliam

asked on

string insert does not work

The following code does not work. Why?

string test=@"test";
string test2=@"xxxxx";
test.Insert(1,test2);

debugger show test="test" after the Insert(..).
ASKER CERTIFIED SOLUTION
Avatar of _TAD_
_TAD_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _TAD_
_TAD_



test.Insert(1,test2) is a function call that returns a string....

in your code above you don't do anything with that string that gets returned
Avatar of samliam

ASKER

I  assign it back to 'test'. So when I look at 'test', it should be "texxxxst"?

yuppers...





<YOUR CODE>

string test=@"test";
string test2=@"xxxxx";
test.Insert(1,test2);      <= look at this line

RESULT =>  test = "test"



<MY CODE>

string test=@"test";
string test2=@"xxxxx";
test = test.Insert(1,test2);    <= look at this line

Result => test = "txxxxxxest"