I
implement
Hi all!
I try to code my own version of replace but it doesn't work. I hope
somebody can help me out.
It only replaces the first char!.
Why I don't use the public string.replace function? Well I love
implementing string functions .
I coded another function for replacing chars in a word and this
function works!
Thank you for any help
Use:
string text = "Good Morning";
replaceStr(text,"Morning","Evening");
Console.WriteLine(text);
Output: Good Eorning // Only the first char
Here is the function
public static void replaceStr(string word, string word2, string
replace)
{
int i;
int x = 0, y, z = 0, l = 0;
char[] place = new char[word.Length];
for (i = 0; i < word.Length; i++)
{
place[x] = word; // fills the place Array
x++;
}
for (y = 0; y < place.Length; y++)
{
if (place[y] == word2[z]) /
{
place[y] = replace[l]; // It only replaces the
first char
l++;
y++;
z++;
}
}
Console.WriteLine(place);
}
I try to code my own version of replace but it doesn't work. I hope
somebody can help me out.
It only replaces the first char!.
Why I don't use the public string.replace function? Well I love
implementing string functions .
I coded another function for replacing chars in a word and this
function works!
Thank you for any help
Use:
string text = "Good Morning";
replaceStr(text,"Morning","Evening");
Console.WriteLine(text);
Output: Good Eorning // Only the first char
Here is the function
public static void replaceStr(string word, string word2, string
replace)
{
int i;
int x = 0, y, z = 0, l = 0;
char[] place = new char[word.Length];
for (i = 0; i < word.Length; i++)
{
place[x] = word; // fills the place Array
x++;
}
for (y = 0; y < place.Length; y++)
{
if (place[y] == word2[z]) /
{
place[y] = replace[l]; // It only replaces the
first char
l++;
y++;
z++;
}
}
Console.WriteLine(place);
}