Multiple replacing emoji decimal to emoji hexadecimal use array swift 4
This below example how to replace data You need to loop, looking to see what the range of the substring
var s = "The Pep Boys are §§§, §§§, and §§§."
var s = "The Pep Boys are §§§, §§§, and §§§."
var arr = ["Manny", "Moe", "Jack"]
while let r = s.range(of:"§§§") {
s.replaceSubrange(r, with: arr.removeFirst())
}
print("\(s)") // The Pep Boys are Manny, Moe, and Jack.
Or use range
Or use range
var s = "The Pep Boys are :§§§;, :§§§;, and :§§§;."
var arr = ["Manny", "Moe", "
while let r = s.range(of: "\\:(.*?)\\;", options: .regularExpression, range: nil, locale: s.replaceSubrange(r, with: arr.removeFirst())
}
print("\(s)")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class EmojiReadViewController: UIViewController { | |
@IBOutlet weak var labelAndroidToIOS: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
var dataFromAndroid = "😊😁 loream ipsum qeqeura dafult" | |
let replace2 = dataAndroid2.replacingOccurrences(of: "[\\&#(.*?)\\;]", with: " ", options: .regularExpression) | |
let array = replace2.components(separatedBy: " ") | |
print(array) | |
var boldKey33: [String] = [] | |
for item in array { | |
if isStringAnInt(string: item) { | |
let dataResult = String(Int(item)!, radix: 16) | |
let str = String(UnicodeScalar(Int(dataResult, radix: 16)!)!) | |
boldKey33.append(str) | |
} else { | |
print("data not a Int \(item)") | |
} | |
} | |
print(boldKey33.description) | |
while let itemEnd = dataAndroid2.range(of: "\\&#(.*?)\\;", options: .regularExpression, range: nil, locale: nil) { | |
dataAndroid2.replaceSubrange(itemEnd, with: boldKey33.removeFirst()) | |
} | |
labelAndroidToIOS.text = dataAndroid2 | |
print("Emoji android(DEC) to IOS(HEX): \(dataAndroid2)") | |
// Important for check data Int in string | |
func isStringAnInt(string: String) -> Bool { | |
return Int(string) != nil | |
} | |
} |
No comments: