• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

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(..).
0
samliam
Asked:
samliam
  • 3
1 Solution
 
_TAD_Commented:


you are missing a critical piece... you have to store the data somewhere...


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


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
0
 
samliamAuthor Commented:
I  assign it back to 'test'. So when I look at 'test', it should be "texxxxst"?
0
 
_TAD_Commented:

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"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now