using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Console
{
class Program
{
static void Main(string[] args)
{
//假設特定字串如下
string subject = "?? 國文(一) Web Development 網路發展";
char[] charArr = subject.ToCharArray();
for (int counter = 0; counter < charArr.Length; counter++)
{
int intValue = Convert.ToInt32(charArr[counter]);
string strHex = String.Format("{0:X}", intValue);
System.Console.WriteLine("字元: {0}, 十進位: {1}, 十六進位: {2}", charArr[counter].ToString(), intValue, strHex);
}
System.Console.Read();
}
}
}
--我自己練習:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As String = "1234這78"
Dim b As Char() = a.ToCharArray
Dim intvalue As Integer
Dim hexstr As String
ListBox1.Items.Clear()
For i As Integer = 0 To b.Length - 1
intvalue = Convert.ToInt32(b(i))
hexstr = String.Format("{0:x}", intvalue)
ListBox1.Items.Add(String.Format("值:{0},十進位:{1},十六進位:{2}", b(i).ToString, intvalue, hexstr))
Next
End Sub
End Class

沒有留言:
張貼留言