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

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

How to convert an Int to a Character in Swift(如何在 Swift 中將 Int 轉(zhuǎn)換為字符)
本文介紹了如何在 Swift 中將 Int 轉(zhuǎn)換為字符的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(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.

問題

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

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

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

生成一個(gè) 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)換為字符的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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 一個(gè) 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?(哪種方法是估計(jì)拍攝物體尺寸的最佳方法?)
Convert Character to Int in Swift 2.0(在 Swift 2.0 中將字符轉(zhuǎn)換為 Int)
Edit Text shows exception Invalid Int quot;quot;(編輯文本顯示異常 Invalid Int “;)
主站蜘蛛池模板: 亚洲欧美久久 | 99爱国产| 成人欧美一区二区三区在线播放 | 欧美成人精品一区二区男人看 | 国产一级大片 | 一起操网站 | 国产精品久久久久久久久久久久午夜片 | 99tv| a级毛片国产 | 免费激情网站 | 欧美影院 | 麻豆精品国产免费 | 中文字字幕在线中文乱码范文 | 日批免费看 | 狠狠综合久久av一区二区小说 | 国内精品久久精品 | 国产精品1区2区3区 中文字幕一区二区三区四区 | 黄色大片在线视频 | 一区二区免费 | 老司机成人在线 | 成人精品毛片国产亚洲av十九禁 | 久久久久久久一区二区三区 | sese视频在线观看 | 日韩在线视频一区 | 国产yw851.c免费观看网站 | 欧美日韩精品久久久免费观看 | 国产精品久久久久久久久久久久久 | 中国一级大毛片 | 草草影院ccyy| 日日操天天射 | 97中文视频 | 熟女毛片 | 成人高清在线视频 | 久久精品国产一区老色匹 | 亚洲久视频| av中文天堂 | 中文字幕亚洲视频 | 国产91在线 | 亚洲 | 日日夜夜精品免费视频 | 国产精品中文 | 嫩草网|