2011年3月13日日曜日

【メモ】C#で指定文字間の一覧を獲得

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            byte b1 = (byte)textBox1.Text[0];
            byte b2 = (byte)(textBox1.Text[1] + 1);
            byte[] by = new byte[b2 - b1];
            for (int i = 0; i < (b2 - b1); i++)
            {
                by[i] = (byte)(b1 + i);
            }
            string c = Encoding.UTF8.GetString(by);
            string s = "";
            for (int i = 0; i < c.Length; i++)
            {
                s = s + "\r\n" + "if (by == '" + c.Substring(i, 1) + "') s += \"" + c.Substring(i,1) + "\";";
            }
            textBox2.Text = s;

            this.Text = textBox1.Text[0] + "~" + textBox1.Text[1] + " 計" + c.Length + "文字";
        }
    }
}

************************
とりあえず動作優先コーディング時間優先なのでところどころ変な動きする

0 件のコメント:

コメントを投稿