Solved

string insert does not work

Posted on 2003-12-10
4
465 Views
Last Modified: 2010-04-16
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
Comment
Question by:samliam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 50 total points
ID: 9916640


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
 
LVL 22

Expert Comment

by:_TAD_
ID: 9916648


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
 

Author Comment

by:samliam
ID: 9916708
I  assign it back to 'test'. So when I look at 'test', it should be "texxxxst"?
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 9917335

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question