0

I'm not sure how to do this in iOS Swift

let test = "fnfsjflsjlkdkfj?v=904kg4"
// search test for ?v= and store everything after ?v= into a new string
let newString = "904kg4"

I want everything after ?v= into a new string, is this possible? if so, how can I accomplish this

1 Answer 1

2

Use rangeOfString to find the range of ?v= and then use substringFromIndex to get the rest of the string:

let test = "fnfsjflsjlkdkfj?v=904kg4"
if let range = test.rangeOfString("?v=") {
    let newString = test.substringFromIndex(range.endIndex)
}
Sign up to request clarification or add additional context in comments.

2 Comments

You can also use the simple method without options.
Thanks @LucianBoboc! Updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.