Swift - ios Replace String - Thay thế ký tự trong chuỗi string

Bài này mình hướng dẫn các bạn thay thế ký tự trong đoạn text string trong ios-swift


  • khởi tạo : var textString :String = "chuỗi sẽ được thay thế 123456 chuỗi "

  • Sủ dụng hàm : textString.stringByReplacingOccurrencesOfString("old", withString: "new")
       - VD: let newtext = textString.stringByReplacingOccurrencesOfString("chuỗi", withString: "ok")
          -> KQ: "ok sẽ được thay thế 123456 ok "

       - let newtext = textString.stringByReplacingOccurrencesOfString("thay thế", withString: "new")
          -> KQ: "ok sẽ được new 123456 ok "

       - let newtext = textString.stringByReplacingOccurrencesOfString("chuỗi", withString: "ok")
          -> KQ: "ok sẽ được thay thế 123456 ok "


Comments

Popular posts from this blog

Tranquil Tunes: Soothing Piano & Guitar Music for Study, Work, Relaxation & Meditation

Resize - Rotate - Move View or image view in swift

NSTimer - Tạo ứng dụng đếm thời gian swift-ios