Last active
March 31, 2023 07:48
-
-
Save 0x30/15abad6afaa0ce6e7d49dd28e705772c to your computer and use it in GitHub Desktop.
城市代码 获取 Emoij , 字符串 拼音 处理
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
// | |
// String+Country.swift | |
// Rate | |
// | |
// Created by 0x30 on 2017/11/20. | |
// Copyright © 2017年 s. All rights reserved. | |
// | |
import Foundation | |
extension String{ | |
/// 根据 城市Code 获取 Emoij 表情 | |
/// | |
/// - Parameter country: 国家代码 | |
/// - Returns: 城市Emoij 表情字符串 | |
static func flag(country:String) -> String { | |
let base : UInt32 = 127397 | |
var s = "" | |
for v in country.unicodeScalars { | |
s.unicodeScalars.append(UnicodeScalar(base + v.value)!) | |
} | |
return String(s) | |
} | |
/// 去掉字符串的前后字符串 | |
/// | |
/// - Returns: 处理后的字符串 | |
func trim() -> String { | |
return self.trimmingCharacters(in: .whitespacesAndNewlines) | |
} | |
/// 将中文 转换为 拼音字符串 | |
/// | |
/// - Returns: 拼音字符串 | |
func toPinYin() -> String{ | |
let string = CFStringCreateMutableCopy(nil, 0, self as CFString); | |
CFStringTransform(string, nil, kCFStringTransformMandarinLatin, false); | |
CFStringTransform(string, nil, kCFStringTransformStripDiacritics, false); | |
if let str = string as String?{ | |
return str.replacingOccurrences(of: " ", with: "") | |
} | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment