C# 全型和半型字體相互轉換

參考來源:MSDN Strings.StrConv 方法

1. 加入參考 Microsoft.VisualBasic

2. 指示詞 using Microsoft.VisualBasic

3. 轉形 Strings.StrConv(Text1.text, VbStrConv.Narrow, 0).ToLower().Trim();

VbStrConv.Narrow :全形轉半形

VbStrConv.Wide:半形轉全形

範列程式

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualBasic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("半型「12345abcde」轉全型「" + Strings.StrConv("12345abcde", VbStrConv.Wide,0)+"」");
            Console.WriteLine("全型「12345abcde」轉半型「" + Strings.StrConv("12345abcde", VbStrConv.Narrow, 0) + "」");
            Console.ReadLine();
        }
    }
}

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s