0
Need help
I want to switch two characters in any position of the string. i.e input hello output helol or input world output wolrd Any characters by just switch their indexes https://code.sololearn.com/cFCascIEZNVG/?ref=app
1 Resposta
0
The simplest way without use substring etc is get a char array for the word, play with chars and return it as string.
// get the word as a char array
// (which ia not immutable)
char[] a= word.ToCharArray();
// save the first char in a temp var
char t= ca[0];
// replace the second first char with the second
ca[0]= ca[1];
// replace the second char with the temp var (old first char)
ca[1]= t;
// return the char array as string
return new string(ca);