Created
April 13, 2019 18:06
-
-
Save Plus1XP/13788f9fcf3bdf9c35f9e9d7936b4b62 to your computer and use it in GitHub Desktop.
Iterates through a string replacing characters with a character of your choice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string ReplaceLetters(string wordToSearch, char letterToFind, char letterToReplace) | |
{ | |
StringBuilder word = new StringBuilder(wordToSearch); | |
int index = 0; | |
foreach (char letter in wordToSearch) | |
{ | |
if (letter.Equals(letterToFind)) | |
{ | |
word.Remove(index, 1); | |
word.Insert(index, letterToReplace); | |
} | |
index++; | |
} | |
return word; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment