Someone please help. *PROBLEM SOLVED* | Sololearn: Learn to code for FREE!
+ 3

Someone please help. *PROBLEM SOLVED*

I have been working on a project, and something happens that's not supposed to. Either that or I'm unbelievably dumb. The code returns 1 even though it should (probably) return two. This only happens in a loop. (Maybe it doesn't, but I need it to be in a loop.) Thanks to everyone here for their help.

19th Sep 2017, 10:52 AM
WdBros - avatar
4 Antworten
+ 20
@WdBros Can you change this statement it will output 2. one=one.Replace(one[0].ToString(), two.ToString());
19th Sep 2017, 11:53 AM
Nithiwat - avatar
+ 16
Why? No error.
19th Sep 2017, 10:54 AM
Nithiwat - avatar
+ 8
You caught me white fluffy cat! ÔŁĄ @luka and @Nithiwat are correct, you just forgot to reassign as the Replace function will return a *NEW* string after replacement. (Remember string is immutable) I just prepared a demo too and hopefully it helps! ­čśä
19th Sep 2017, 12:06 PM
Zephyr Koo
Zephyr Koo - avatar
+ 6
Additional info; Convert.ToChar(int) returns a Unicode character based on the value of the integer passed in. Convert.ToChar(65) outputs 'A', instead of '65'. Your code Convert.ToChar(two) returned a non printable character.
19th Sep 2017, 11:26 AM