vkarri1 vkarri1 - 3 months ago 6
C# Question

I am trying to replace "1" in the String "original" with 2, 3, 4,.........95

So my output should be the string printed 95 times.

Sample Output:

Ven is 1
Ven is 2
.
.
.
Ven is 95

namespace Increment
{
class Program
{
public static void Main()
{
String original = "ven is 1";

for (int k = 2; k <= 95; k++)
{
String s = original.Replace("1", k);
Console.WriteLine("The modified string: '{0}'", s);
}
}
}
}

Answer

The second parameter of Replace can't be an integer, it should be a string.

So, instead of

String s = original.Replace("1", k);

do this:

String s = original.Replace("1", k.ToString());

See it working.