_davidharris
asked on
Changing an individual character within a string
I've been struggling with this for a while. It's such a simple question that I've been reluctant to ask it.
How do you change an individual character within a string without replace or substring/remove in visual c++ .net?
The .net equivalent of :
st[index] = '\newvalue';
I have to use this method because the file I have a problem with needs extra carriage returns filtered out of it and the newline/carriage return's that are in the right place left alone.
I thought about this:
arbSt = mainSt->Substring(indexOfE xtraCrLf - 10, 20); // arbitrary length to make sure replace doesn't replace everything
tmpSt = mainSt->Substring(beginnin g - 10, 20)->Replace("\r\n", " ");
mainSt->Replace(arbStr, tmpSt);
That would work, but I'd rather know a better way so I don't end up doing that for every typo within my source file.
Thanks!
_david
How do you change an individual character within a string without replace or substring/remove in visual c++ .net?
The .net equivalent of :
st[index] = '\newvalue';
I have to use this method because the file I have a problem with needs extra carriage returns filtered out of it and the newline/carriage return's that are in the right place left alone.
I thought about this:
arbSt = mainSt->Substring(indexOfE
tmpSt = mainSt->Substring(beginnin
mainSt->Replace(arbStr, tmpSt);
That would work, but I'd rather know a better way so I don't end up doing that for every typo within my source file.
Thanks!
_david
.NET string object is immutable, this means, it's value cannot be changed once it is created. Functions like Trim, Replace, Substring return new string instance and don't change original string.
ASKER
Is there a way to change that string into an array of bytes and then change the byte value, and then convert (or dump the byte array to a file) the byte array to a string?
_david
_david
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I just ended up using replace and substring. Thanks for your help!
_david
_david
ASKER
// check each field for characters that are not alphanumeric or punctuation
for (char_i = 0; char_i != field->Length; char_i++)
if (!(Char::IsLetterOrDigit(f
field = field->Replace(field[char_
That's what I ended up with! Which works just the same.
_david