开发者

Saving files with slash in file name - objective-c

I can't save file with slash in file name. I download file, and if file has slash in the name, it doesn't want to save. For example full name of the song: "H/F ArtistName - Song name.mp3". Is it possible to save files with slash in name? Or how to properly开发者_JAVA百科 replace slash?


From another post:

    NSString *s = @"foo/bar:baz.foo";
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"/:."];
s = [[s componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
NSLog(@"%@", s); // => foobarbazfoo

or just look here


/ is generally used as a separator between files or folders in the operating system. therefore the filename can not contain a slash as that would confuse the H in the name for a folder.

The best idea is to replace it with a whitespace or simple delete it to give: "HF ArtistName - Songname.mp3"


workaround:

Xcode 12.3, iOS 14

fileName.replacingOccurrences(of: "/", with: ":") // 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜