LoginSignup
6
6

More than 5 years have passed since last update.

[iOS8] Swiftで文字列の任意の範囲(Range)を削除する方法

Last updated at Posted at 2014-12-05

Swiftで文字列の任意の範囲(Range)を削除する方法をサンプルコードで説明します。

条件

・可変する為、NSMutableStringで宣言
・先頭が0,1...とした削除スタート地点の指定(location)
・削除する文字数の指定(length)

let str:NSMutableString = "Hello World!"                     // "Hello World"
str.deleteCharactersInRange(NSRange(location: 0,length: 5))  // " World"
6
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6