[英]Convert integer to character and vice versa
如何在“Dynamic C”中將整數轉換為char,反之亦然。
使用VB.NET如下:
Dim i As Integer
Dim c As Char
' Integer to Character
i = 302
c = ChrW(302)
Debug.Print(c) 'Result: Į
' Character to Integer
Dim j As Integer
j = AscW(c)
Debug.Print(CStr(j)) ' Result: 302
謝謝
由於int和char都是整數類型,因此您只需將適當值的整數分配給char,反之亦然:
int i = 65; // 'A'
char c = 'B'; // 66;
int cAsInt = (int)c; // 66 = 'B'
char iAsChar = (char)i; // 'A' = "65"
如果要解析一個字符,使'1'成為整數1,則可以使用itoa
和atoi
。
如果你想在ascii值和它們的字符之間進行轉換,那就更容易了。 只需將int轉換為char或將char轉換為int。
為什么不使用可用於UCS2的其他類型的uint16_t? 我的意思是char用於ascii並擴展0-255~uint8_t,如果你需要更多不使用char。
uint16_t c=302;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.