Skip to content

Instantly share code, notes, and snippets.

@anoop4real
Created September 13, 2017 17:57
Show Gist options
  • Save anoop4real/472270a5defb0a521a3dba0a2daba65b to your computer and use it in GitHub Desktop.
Save anoop4real/472270a5defb0a521a3dba0a2daba65b to your computer and use it in GitHub Desktop.
let string = "This a string split using * and this is left."
if let range = string.range(of: "*") {
let lastPartIncludingDelimiter = string.substring(from: range.lowerBound)
print(lastPartIncludingDelimiter) // print * and this is left.
let lastPartExcludingDelimiter = string.substring(from: range.upperBound)
print(lastPartExcludingDelimiter) // print and this is left.
let firstPartIncludingDelimiter = string.substring(to: range.upperBound)
print(firstPartIncludingDelimiter) // print This a string split using *
let firstPartExcludingDelimiter = string.substring(to: range.lowerBound)
print(firstPartExcludingDelimiter) // print This a string split using
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment