Teeheez
Teeheez

Reputation: 43

Typing things Backwards

My teacher has asked us to take a sentence that we input and make the console write it backwards. I understand that step is probably the best way to do it, but I am confused when it comes to the other parts. I also believe that I'll need to use an array.

For i = 8 To 1 Step -1

    Console.WriteLine(myarray(i - 1))

Next

Console.ReadLine()

This is the code I am going to try and base the program on. Any tips?

Upvotes: 0

Views: 103

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460138

A string is already an implicit Char().

Dim sentence = "Hello World"
For i = sentence.Length - 1 To 0 Step -1
    Console.Write(sentence(i))
Next

or, if you can use LINQ

Dim backwards = sentence.Reverse()
Dim bwSentence = New String(backwards.ToArray())

Upvotes: 2

Related Questions