C 數字轉字母,ASCII碼轉換

2022-06-17 16:48:07 字數 1129 閱讀 9229

字母轉換成數字

byte array = new byte[1];   //定義一組陣列array

array = system.text.encoding.ascii.getbytes(string); //string轉換的字母

int asciicode = (short)(array[0]); /* 何問起 hovertree.com */

ascii碼 = convert.tostring(asciicode); //將轉換一的ascii碼轉換成string型

數字轉換成字母

byte array = new byte[1];

array[0] = (byte)(convert.toint32(ascii碼)); //ascii碼強制轉換二進位制

轉換後的字母= convert.tostring(system.text.encoding.ascii.getstring(array));

在編碼的過程中很多時候會用到將某些數字的索引轉化為字母,比方說excel的單元格的列數在excel中就用大寫字母來表示,要把數字轉換成字母可以使用c#的asciiencoding類裡的getstring方法。請參見以下示例:

/// 

/// 數字轉字母

///

/// 要轉換成字母的數字(數字範圍在閉區間[65,90])

///

private string nuntochar(int number)

; return asciiencoding.getstring(btnumber);

}return "數字不在轉換範圍內";}

///

/// 把1,2,3,...,35,36轉換成a,b,c,...,y,z

///

/// 要轉換成字母的數字(數字範圍在閉區間[1,36])

///

private string nunbertochar(int number)

; return asciiencoding.getstring(btnumber);

}return "數字不在轉換範圍內";

}/* 何問起 hovertree.com */

**:

C 單純的字母數字ASCII碼轉換

字母轉換成數字 byte array new byte 1 定義一組陣列array array system.text.encoding.ascii.getbytes string string轉換的字母 int asciicode short array 0 何問起 hovertree.com a...

C 字元轉ASCII碼,ASCII碼轉字元

今天用到這個,網上找了個不錯的,轉過來以備後用!字元轉ascii碼 public static int asc string character else ascii碼轉字元 public static string chr int asciicode string strcharacter asc...

和 字母數字對應的ASCII碼。

列印a z a z 0 9對應的ascii碼。system.out.println a int a system.out.println z int z system.out.println system.out.println a int a system.out.println z int z ...