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....
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 : )
+ 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");
+ 2
Ipang hey thanks....it was a little mistake... You saved my time..cheers
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
0
You are very welcome DataStream Cowboy, keep it going buddy â
0
Hi I will like to how I create my own code