0

For example i have String of "version/ofswift/developer". and i want print which starts from back side until the specific index like my specific index will be "/" then the answer should be "developer". What code snippet would do that, and being the most swift-like? I can't find any good practice. I hope you will help me to figure it out. Thank In Advance.

7
  • show us what have you tried? past your code Commented May 23, 2018 at 13:28
  • There is a function something like “separatedBy” but I can’t think what it is right now. Take a look at String docs for Swift. Commented May 23, 2018 at 13:28
  • @Pratik i have tried with subStrig method. But it is not like i am expected. Commented May 23, 2018 at 13:42
  • @Fogmeister yes, i will be checking with that. Commented May 23, 2018 at 13:42
  • That looks like a file path – in that case you should URL and lastPathComponent Commented May 23, 2018 at 13:45

1 Answer 1

1

Use String method components(separatedBy:) to produce an array and then get the last element using last

let string = "version/ofswift/developer"
let lastComponent = string.components(separatedBy: "/").last
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.