首页 > 代码库 > swift

swift

1.汉字转拼音

func pinYinZChines(content:String)->String{
     
    let transformContents = CFStringCreateMutableCopy(nil, 0, content)
     
    CFStringTransform( transformContents, nil, kCFStringTransformMandarinLatin, false)
     
    CFStringTransform( transformContents, nil, kCFStringTransformStripDiacritics, false)
     
    let ztransformContents = transformContents as String
     
    let index = ztransformContents.startIndex.advancedBy(0)
     
    let firstString = ztransformContents[index]
     
    let stringZ = String.init(firstString)
     
    return stringZ.uppercaseString
     
}

swift