Solved

string insert does not work

Posted on 2003-12-10
4
432 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Contant UI messages in .NET 1 41
Any reason why this might be bad? 7 41
Check my code out(2) 1 35
Get String split 5 33
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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now