3

I am working with LISP expressions in my computer programming (visual basic) course and I have a minor question.

How would I go about reversing a list in vb.net?

For example, if I were to input:

'(H J K L)

I would return an output of:

'(L K J H)
Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
Augment
  • 29
  • 1
  • 2

1 Answers1

5

if for instance you have a list of strings, you can simple call the Reverse() method which is available for IEnumerable

Dim list = New List(Of String)() From { _
    "item", _
    "item2", _
    "item3" _
}

list.Reverse()

Or if you were dealing with an array of strings it would be as below.

Dim arr = New String() {"kdkd", "dkd"}

Dim reversedArr = arr.Reverse()
scartag
  • 17,548
  • 3
  • 48
  • 52
  • And if you have a string that looks like "(H J K L)", you should be able to use the Trim and Split methods of the String Class to convert it into an array of String {"H", "J", "K", "L"}. – Blackwood Feb 04 '15 at 00:02