deepak kumar deepak kumar - 22 days ago 5
iOS Question

How to get data from string after particular backslash?

I have a string such as

\home\var\path\uplaod\abc.png
. Now I want to get data from uplaod onwards. Please suggest any function or code?

Answer

If path of image is not fixed or order of uplaod is not specific try like this.

let string = "\\home\\var\\path\\uplaod\\abc.png"
if let range = string.range(of: "uplaod") {
    let imagePath = string.substring(from: range.lowerBound)
    print(imagePath)
}

Output

uplaod\abc.png