By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,056 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,056 IT Pros & Developers. It's quick & easy.

char replace in string

P: n/a
Bob
Is there a way to replace a character in a string without having the
framework allocate a new string the way string.Replace does?

I need the below code to work, alothough it says the indexer is read only.

string B = "412345";
B[0]='0';

The reason is for pure performance. I am doing a lot of changes and can't
have it allocate a new string every time its modified.

Bob
Sep 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Bob wrote:
Is there a way to replace a character in a string without having the
framework allocate a new string the way string.Replace does?
No. Strings are immutable.
I need the below code to work, alothough it says the indexer is read only.

string B = "412345";
B[0]='0';

The reason is for pure performance. I am doing a lot of changes and can't
have it allocate a new string every time its modified.
You may wish to consider using a StringBuilder instead, or a char array
if that can perform all the changes you require.

Jon

Sep 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.