Objective-C: パス文字列からファイル名を抽出する 質問する

Objective-C: パス文字列からファイル名を抽出する 質問する

Objective-C メソッドを使用NSStringして/Users/user/Projects/thefile.ext抽出したい場合。thefile

それを実行する最も簡単な方法は何ですか?

ベストアンサー1

NSString リファレンスから取得すると、以下を使用できます。

NSString *theFileName = [[string lastPathComponent] stringByDeletingPathExtension];

呼び出しlastPathComponentは を返しthefile.ext、 はstringByDeletingPathExtension末尾から拡張子サフィックスを削除します。

おすすめ記事