久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Swift 中將 Int 轉(zhuǎn)換為字符

How to convert an Int to a Character in Swift(如何在 Swift 中將 Int 轉(zhuǎn)換為字符)
本文介紹了如何在 Swift 中將 Int 轉(zhuǎn)換為字符的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我在這里掙扎和失敗了十多分鐘,我屈服了.我需要在 Swift 中將 Int 轉(zhuǎn)換為 Character,但無法解決.

I've struggled and failed for over ten minutes here and I give in. I need to convert an Int to a Character in Swift and cannot solve it.

問題

你如何將一個 Int (integer) 轉(zhuǎn)換 (cast) 為一個 Character (char) 在 Swift 中?

How do you convert (cast) an Int (integer) to a Character (char) in Swift?

說明性問題/任務(wù)挑戰(zhàn)

生成一個 for 循環(huán),打印字母 'A' 到 'Z',例如像這樣:

Generate a for loop which prints the letters 'A' through 'Z', e.g. something like this:

    for(var i:Int=0;i<26;i++) {      //Important to note - I know 
        print(Character('A' + i));   //this is horrendous syntax...
    }                                //just trying to illustrate! :)

推薦答案

不能將整數(shù)直接轉(zhuǎn)換為 Character 實(shí)例,但可以從整數(shù)轉(zhuǎn)換為 UnicodeScalarCharacter 并再次返回:

You can't convert an integer directly to a Character instance, but you can go from integer to UnicodeScalar to Character and back again:

let startingValue = Int(("A" as UnicodeScalar).value) // 65
for i in 0 ..< 26 {
    print(Character(UnicodeScalar(i + startingValue)))
}

這篇關(guān)于如何在 Swift 中將 Int 轉(zhuǎn)換為字符的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw stars using Quartz Core?(如何使用 Quartz Core 繪制星星?)
Why does giving addArcWithCenter a startAngle of 0 degrees make it start at 90 degrees?(為什么給 addArcWithCenter 一個 0 度的 startAngle 使它從 90 度開始?)
Find the CGPoint on a UIView rectangle intersected by a straight line at a given angle from the center point(在與中心點(diǎn)成給定角度的直線相交的 UIView 矩形上找到 CGPoint)
Which is the best way to estimate measure of photographed things?(哪種方法是估計拍攝物體尺寸的最佳方法?)
Convert Character to Int in Swift 2.0(在 Swift 2.0 中將字符轉(zhuǎn)換為 Int)
Edit Text shows exception Invalid Int quot;quot;(編輯文本顯示異常 Invalid Int “;)
主站蜘蛛池模板: 91精品一区二区三区久久久久久 | 超碰在线亚洲 | 999免费观看视频 | 欧美二区三区 | 天堂在线中文 | 九一国产精品 | 日韩在线播放视频 | 国产视频一区二区 | 91久久精品国产91久久性色tv | 国产精品免费播放 | 97精品视频在线观看 | 午夜天堂精品久久久久 | 欧美精品在线播放 | 日韩中文字幕在线播放 | 干干干日日日 | 欧美日韩综合视频 | 九九九久久国产免费 | 777zyz色资源站在线观看 | 国产精品福利在线观看 | 亚洲成人免费在线观看 | 欧美一级特黄aaa大片在线观看 | 久久一二区 | 狠狠干五月天 | 96av麻豆蜜桃一区二区 | 四虎影音 | 农村妇女毛片精品久久久 | 福利视频1000 | 成人久久 | 欧美日韩在线一区二区 | 美女中文字幕视频 | 黄色中文字幕 | 国产一区二区在线视频 | 亚洲精品三级 | 一区二区在线不卡 | 中文字幕在线观看一区二区 | 国精品一区二区 | 激情六月丁香 | 久久久精品日本 | 毛片一级片 | 中文字幕一区二区三区精彩视频 | 午夜免费精品视频 |