473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

char replace in string

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
1 1676
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sieg1974 | last post by:
Hi, I have made this simple program to understand char ** pointers, but I still having many questions. int main() { char ** testPointerPointerChar = 0; char * A = "string01";
33
by: apropo | last post by:
what is wrong with this code? someone told me there is a BAD practice with that strlen in the for loop, but i don't get it exactly. Could anyone explain me in plain english,please? char...
13
by: baumann.Pan | last post by:
when define char *p = " can not modify"; p ='b' ;is not allowed, but if you declare p as char p = "can modify"; p = 'b'; is ok? why?
7
by: VMI | last post by:
If I have the string "Héllo", how can I replace char (é) with an 'e'? I cannot use the String.Replace() fuction. It has to be by replacing one char with another. Thanks.
12
by: anonymous | last post by:
Hello, I need to replace this char  with another char. However I am not able to acieve this. I tried this but it doesnt work: str = str.Replace(chr(asc(194)), "") Can somebody help ?
7
by: GysAnn | last post by:
Hello, I'm looking for a function for converting the input to a regular text. Example: when the input is "aBCdefgHI jkLM ooPP" the return value of the function should be "Abcdefghi Jklm...
10
by: tommaso.gastaldi | last post by:
I am extracting some field names from a table of a db (it's an OledbSchemaguid table). It occurs for some OleDbSchema driver that NameDBField = cstr(DataRow.Item(3)) return a string that is...
7
by: owolablo | last post by:
Can anybody please tell me how to change the individual elements of a char variable. I need to parse through the string, check for a particular character and change it to something else if it is...
13
by: Hongyu | last post by:
Hi, I have a datetime char string returned from ctime_r, and it is in the format like ""Wed Jun 30 21:49:08 1993\n\0", which has 26 chars including the last terminate char '\0', and i would...
2
by: anii | last post by:
Hi there, I've got this piece of code, but I'm having trouble getting it to write the changes into the file. What I'm trying to do is: Read text file Find user specified character (eg. what...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.