friendsterTalk - Friendster Forum

friendsterTalk - Friendster Forum

Welcome guest! Please Login or Register.

#1  2008-11-11 17:28:34

creamownedz
 active server protocol
creamownedz's display avatar
» FriendsterTalker
PsychoCoder
Class-S
Location: Ftalk & MCTF
Registered: 2008-03-22
Posts: 115
Last visit: Yesterday
Reputation: 7

Replace a character in a string depicted by an index [c#]

Replaces a character in a string with a new character.

Instructions:
1) Copy and paste this snippet into a class.
2) Read the example usage.


Code:

// Replaces a character in a string with the character specified.
void replaceCharWithChar(ref string text, int index, char charToUse)
{
    char[] tmpBuffer = text.ToCharArray();
    buffer[index] = charToUse;
    text = new string(tmpBuffer);
}

// Example Usage
string helloWorld = "Hello World";
replaceCharWithChar(helloWorld, 0, helloWorld[0].ToLower());

EDIT: Changed the example to turn the first character into a lower case character instead of an upper case character.. how silly of me. =}


...Giving of reputation are highly appreciating for me...
Computers don't make errors what they do they do on purpose
...computer is my expertise...
....an addicted coder....
....don't ripp all my tutorials....

Search Friendstertalk

Board footer

FriendsterTalk is not affiliated with Friendster.com
Copyright © 2002–2009 PunBB

[ 8 queries - 0.024 second ]

Pay Per Click Ads by pay per click advertising by Kontera

FriendsterTalk.com x

Welcome to FriendsterTalk! You'll need to login in order to fully use all the features and view all the sections of this site.

Please register if you're not yet a member. =)