0% found this document useful (0 votes)
26 views1 page

Replacement 222

This C# program takes a string "This is a Cow" as input. It finds the index of " is " in the string and replaces the characters " is " with " was " by modifying the character array. It then constructs a new string from the modified character array and prints the output "This was a Cow".

Uploaded by

Fasih Dawood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Replacement 222

This C# program takes a string "This is a Cow" as input. It finds the index of " is " in the string and replaces the characters " is " with " was " by modifying the character array. It then constructs a new string from the modified character array and prints the output "This was a Cow".

Uploaded by

Fasih Dawood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

namespace ConsoleApplication2

class Program

static void Main(string[] args)

string str = "This is a Cow";

Console.WriteLine("Before Replacing is : "+str);

char[] toChangeChar = str.ToCharArray();

int charIndex = str.IndexOf(" is ");

if (charIndex != -1)

toChangeChar[charIndex++] = ' ';

toChangeChar[charIndex++] = 'w';

toChangeChar[charIndex++] = 'a';

toChangeChar[charIndex] = 's';

string ustr = new string(toChangeChar);

Console.WriteLine("After Replacing Is as Was: "+ustr);

Console.ReadKey();

You might also like