1
我是Swift中的新成員,我很多RND,但無法取得成功。我有替換字符串範圍我使用這個代碼,但它的返回錯誤我使用SWIFT 2.0Swift change帶範圍&和shouldChangeTextInRange的字符串如何知道退格
let aString: String = txt_description.text
let newString = aString.stringByReplacingOccurrencesOfString(varattherate, withString:"@\(getText) ", options: NSStringCompareOptions.LiteralSearch, range: NSMakeRange(0, 10))
有急性的問題是,我已經取代從字符串 文字我的字符串是「我的名字是@Test但我想改變@te」和替換 ‘@te’與取代‘@測試’,但我對最後的改變‘@te’字符串的,我嘗試創建‘自動填充文本視圖’
但我使用這個代碼
let aString: String = "my name is @test but i want change @te"
let newString = aString.stringByReplacingOccurrencesOfString(varattherate, withString:"@\(getText) ", options: NSStringCompareOptions.LiteralSearch, range:nil)
和輸出是「我的名字是@testst,但我想改變@test」 但我有需要輸出「我的名字是@test但我想改變@test」不改變第一@te只有最後一個與動態
第二問題改變的是 如何在這個函數退格知道
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool
{
}
我試試這個代碼,但不工作 文本:字符串) - >布爾{
if(text == "\b") {
println("This is backspace ")
return false
}
}