I store some files in file manager and I need three data string in their name that I can do the necessary modification, they data I need are two ids and one timestamp, something like that
"hdh3npHvjjkdfydlz-jfoabcotmdbnadp-1657155181"
I want to read each of them separately, those three data is separated by one – and the number of the characters may be not the same for different files. Can anyone help me to do that?
>Solution :
If I understand you correctly, you want to extract each piece of info from the string using a hyphen as a delimiter? If so, you could use:
import UIKit
let myString = "hdh3npHvjjkdfydlz-jfoabcotmdbnadp-1657155181"
let components = myString.components(separatedBy: "-")
for c in components {
print(c)
}
Or alternatively:
let items = myString.split(separator: "-")
for i in items {
print(i)
}
Either one will separate the string into individual pieces using the hyphen as a delimiter.