-1

I have this string

let data = 123,456,7,8,9,10 

I want to extract the last value separated by a "," which in this case would be 10, and its not necessarily a two digit value.

I tried this:

var data = 123,456,7,8,9,10 data = data.last! 
1
  • 3
    You must have tried something ... don't hesitate to show your attempt! Commented Nov 16, 2017 at 9:37

1 Answer 1

2

Use String method data.components(separatedBy:)

let data = "123,456,7,8,9,10" let lastComponent = data.components(separatedBy: ",").last print(lastComponent) 
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.