C# | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

C#

What should i do if i want to Reverse String ? Ex: string name= null; name=textBox1.text; After that what should i do? Thanks

13th Jul 2017, 1:38 PM
lee ratana
8 Respostas
+ 1
string name = "", eman = ""; int nameLen; nameLen = name.Length - 1; while (nameLen >= 0) { eman = eman + name[nameLen]; nameLen--; }
13th Jul 2017, 1:51 PM
AgentSmith
+ 1
https://code.sololearn.com/cw8P6mr0B6xh/#cs ^I always forget about the playground. There it is in action, if you wish to check it out. Basically, you reverse it by creating a secondary string variable that we'll store the new word in, and then just iterate backward through the first string array, capturing the letter in each index and storing it in the secondary string variable. Hope that helps. string name = "", eman = ""; int nameLen; Console.Write("What's your name? \n"); name = Console.ReadLine(); nameLen = name.Length - 1; while (nameLen >= 0) { eman = eman + name[nameLen]; nameLen--; } Console.WriteLine("Your name forward is {0}\n", name); Console.WriteLine("Your name backward is {0}\n", eman);
13th Jul 2017, 1:52 PM
AgentSmith
+ 1
When you're done, just assign the value of 'eman' to the variable 'name.' string name = "", eman = ""; int nameLen; nameLen = name.Length - 1; while (nameLen >= 0) { eman = eman + name[nameLen]; nameLen--; } name = eman; You don't have to continue using eman, it's just necessary to use it as a temporary variable so you can do the operations you need to do.
13th Jul 2017, 2:04 PM
AgentSmith
+ 1
Remove null
3rd Dec 2019, 8:23 PM
Š¼Šøр 111
Š¼Šøр 111 - avatar
0
If we don't want to use string 2 . Ex: string name ,eman; how to do this ?
13th Jul 2017, 1:58 PM
lee ratana
0
Thank you sir
13th Jul 2017, 2:11 PM
lee ratana
0
Wow so good ,,, thanks sir
13th Jul 2017, 10:58 PM
lee ratana
0
I want to ask you one more about Pair Letter , Example : book it is Pair letter Car it is not Pair letter ,, how do we know about this? Should we must do modulus or not ?
14th Jul 2017, 10:40 AM
lee ratana