+ 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. https://code.sololearn.com/cOQZ6KZ1PnZe/?ref=app

19th Sep 2017, 10:52 AM
WdBros
WdBros - avatar
4 Antworten
+ 20
@WdBros Can you change this statement it will output 2. one=one.Replace(one[0].ToString(), two.ToString()); https://code.sololearn.com/cmX4iyineGKr/?ref=app
19th Sep 2017, 11:53 AM
Nithiwat
Nithiwat - avatar
+ 16
Why? No error.
19th Sep 2017, 10:54 AM
Nithiwat
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! 😄 https://code.sololearn.com/cX112mbF0hcW/?ref=app
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. https://msdn.microsoft.com/en-us/library/3hkfdkcx(v=vs.110).aspx
19th Sep 2017, 11:26 AM
Ipang