2011-07-13 5 views
0

アプリ内私はドキュメントディレクトリにサーバーからイメージを保存しています。 ":19:27.png image4_12" 画像 "はimage4_12/19/27.png" として保存されたドキュメントディレクトリのフォルダにIphone:ドキュメントディレクトリに保存されているイメージに関する問題?

どのように画像変換」の画像のように来ているデータベースで

image4_12:19:27.png "から" image4_12/19/27.png "に変更してください。

どうすればよいですか?

答えて

3

ファイル名を:で区切られた部分に分割して後で追加することができます。

NSString * fileName = @"image4_12:19:27.png"; 
NSArray * components = [fileName componentsSeparatedByString:@":"]; 

NSString * relativeFilePath = [components componentsJoinedByString:@"/"]; 
NSString * absoluteFilePath = [documentsDirectory stringByAppendingPathComponent:components]; 

ここで、documentsDirectoryは、ドキュメントディレクトリへのパスです。

+0

素晴らしいですが、次の文字列からイメージ名を取得するにはどうすればよいですか? '/'/Users/taxsmart6/Library/Application Support/iPhone Simulator/4.3/Applications/F47B24BB-B480-4154-A2EB-BA6B445B9455/Documents/image1_04:24:28.png "; ' –

+0

これは' sourceFilePath'にあるとします。次に、 'fileName = [sourceFilePath lastPathComponent];'はファイル名を与えます。 –

+0

'componentsSeparatedByString'は配列を返します。 –

関連する問題