Search This Blog

Saturday, September 23, 2017

How reverse String in Swift

There is simple way to make reversed string

import UIKit

var str = "Hello, playground"

// First way
print(String(str.reversed()))

//Second way
var charArray: [Character] = [Character]()
for ch in str {
    charArray.append(ch)
}

var reversedArray: [Character] = [Character]()

for i in (0..<str.count).reversed() {
    reversedArray.append(charArray[i])
}

print(String(reversedArray))

4 comments:

  1. It was not an easy topic to elaborate in such a short span of time. Custom Website is such a complex topic but you made it easy to understand

    ReplyDelete
  2. Thank you very much for drawing my notice to this. Your blog is jam-packed with helpful information. Unless I read it, I'd have no idea. I'll be back for more great content. Wishing you the best of luck and prosperity. Best Custom Websites

    ReplyDelete
  3. Thank you very much for sharing this informational blog.I could not find such kind of information in any other site.I'll come back for more fantastic material.
    Best wishes, and good luck.
    Custom Website

    ReplyDelete
  4. Good content. I was looking for this type of content. Saved my time for further search.
    You should always provide that type of content. I appreciate your determination to give the students a good title.Custom Designed Websites

    ReplyDelete