SourceCode/PROMS/DataLoader/frmCntTkn.cs

71 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using VEPROMS.CSLA.Library;
namespace DataLoader
{
public partial class frmCntTkn : Form
{
private Dictionary<char, int> dicCharCount;
public frmCntTkn()
{
InitializeComponent();
}
private void CountChars(string txt)
{
foreach (char ch in txt)
{
//'A' is a newline
int ich = Convert.ToInt32(ch);
if (ich == 0xD) Console.WriteLine("D is {0}", txt);
if (ich == 0x17) Console.WriteLine("17 is {0}", txt);
if (!dicCharCount.ContainsKey(ch))
dicCharCount[ch] = 1;
else
dicCharCount[ch] = dicCharCount[ch] + 1;
}
}
//private void ProcessText()
//{
// TextMInfoList txtMList = TextMInfoList.Get();
// foreach (TextMInfo txtM in txtMList)
// {
// string thetext = txtM.TextMValue;
// CountChars(thetext);
// }
//}
private void button1_Click(object sender, EventArgs e)
{
// Create a dictionary that stores characters
// read in data from dbf
// list chars
dicCharCount = new Dictionary<char, int>();
//ProcessText();
// now display dictionary results..
Console.WriteLine("Char\t\tHex\t\tDec\t\tCount");
foreach (char ch in dicCharCount.Keys)
{
// if character is a 'token' and not a hardspace (A0), linefeed (A), RO token (15)
// Transition tokens (0x252c & -x2566) then show it.
if ((ch < 0x20 || ch > 0x7E) && ch!= 0xA0 && ch != 0xA && ch != 0x15 && ch != 0x252C && ch != 0x2566)
{
int ich = Convert.ToInt32(ch);
string cntstr = String.Format("{0}\t\t{1}\t\t{2}\t\t{3}", ch, ich.ToString("X4"), ich.ToString(), dicCharCount[ch]);
listBox1.Items.Add(cntstr);
Console.WriteLine(cntstr);
}
}
}
}
}