0

Why does my a.Replace() method not work here??

static void Main(string[] args) { string a = "love you"; a=a.Replace(" love" , "hate"); Console.WriteLine(a); } //output love you.....why it didnt replace love with hate to give output of " hate you"? Please help me here....

20th Aug 2019, 9:47 PM
DataStream Cowboy
DataStream Cowboy - avatar
8 Answers
+ 5
That's right John Doe's Johnny Thankfully this was a small code, so finding it with only our eyes is still possible : )
21st Aug 2019, 3:18 AM
Ipang
+ 4
DataStream Cowboy , It didn't work because string <a> doesn't contain " love" (notice the space before the 'love'). It will work if you wrote: a = a.Replace("love", "hate"); Again, notice there shouldn't be any space before the word 'love'. (Edit) To have " hate you" as output, you place the space before the word 'hate' as follows: a = a.Replace("love", " hate");
21st Aug 2019, 3:10 AM
Ipang
+ 2
Ipang hey thanks....it was a little mistake... You saved my time..cheers
21st Aug 2019, 5:25 PM
DataStream Cowboy
DataStream Cowboy - avatar
0
Cbr✔[ Most active ] i still didnt get you..... Replace is a method then why should i write replace as you stated..or am wrong again
20th Aug 2019, 9:57 PM
DataStream Cowboy
DataStream Cowboy - avatar
0
You are very welcome DataStream Cowboy, keep it going buddy ✌
21st Aug 2019, 5:37 PM
Ipang
0
Hi I will like to how I create my own code
21st Aug 2019, 7:41 PM
Agbanyo Seth