0

I need to swap the first and second character.

Can someone please explain this? https://code.sololearn.com/cuZDCSXYQ9L3/?ref=app

31st Oct 2022, 2:50 AM
Mozzie
Mozzie - avatar
4 Antworten
+ 3
The Substring method (int,int) accept as first param the start index and as second the length of substring then yiur code get the original string least last two chars + the last + the one to last. Use the following return
quot;{s1[1]}{s1[0]}"+s1.Substring(2);
31st Oct 2022, 5:39 AM
KrOW
KrOW - avatar
+ 2
It use string interpolation (see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated ) and essentially create a new string concatenint the original second char (s[1]), the original first char (s[0]) and the substring starting to index 2 from original (s1.Subtring(2))
31st Oct 2022, 5:51 AM
KrOW
KrOW - avatar
0
KrOW Can you desribe it more in laymern term? your code?
31st Oct 2022, 5:44 AM
Mozzie
Mozzie - avatar
0
is it possible to not use string interpolation?
31st Oct 2022, 8:21 AM
Mozzie
Mozzie - avatar