【发布时间】:2011-07-13 07:10:23
【问题描述】:
在应用程序中。我正在将服务器中的图像保存在文档目录中。
在数据库中,图像以“image4_12:19:27.png”的形式出现
在文件目录文件夹中,图像存储为“image4_12/19/27.png”
该图像如何在文档目录中将“image4_12:19:27.png”转换为“image4_12/19/27.png”。
我该怎么办?
【问题讨论】:
标签: iphone objective-c cocoa-touch ios4
在应用程序中。我正在将服务器中的图像保存在文档目录中。
在数据库中,图像以“image4_12:19:27.png”的形式出现
在文件目录文件夹中,图像存储为“image4_12/19/27.png”
该图像如何在文档目录中将“image4_12:19:27.png”转换为“image4_12/19/27.png”。
我该怎么办?
【问题讨论】:
标签: iphone objective-c cocoa-touch ios4
您可以将文件名拆分为以: 分隔的部分,然后再附加它们。
NSString * fileName = @"image4_12:19:27.png";
NSArray * components = [fileName componentsSeparatedByString:@":"];
NSString * relativeFilePath = [components componentsJoinedByString:@"/"];
NSString * absoluteFilePath = [documentsDirectory stringByAppendingPathComponent:components];
其中documentsDirectory 是文档目录的路径。
【讨论】:
"/Users/taxsmart6/Library/Application Support/iPhone Simulator/4.3/Applications/F47B24BB-B480-4154-A2EB-BA6B445B9455/Documents/image1_04:24:28.png";
sourceFilePath。然后fileName = [sourceFilePath lastPathComponent]; 应该给你文件名。
componentsSeparatedByString 它返回数组。