基本信息
源码名称:C#版字典生成器
源码大小:0.68M
文件格式:.zip
开发语言:C#
更新时间:2017-06-17
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 3 元 
   源码介绍
C#版字典生成器

/*
 * 由SharpDevelop创建。
 * 用户: 以夕阳落款
 * 日期: 2017/4/21
 * 时间: 14:37
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace 字典生成
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		private List<string> info;
		private List<string> result;
		// 保存文本文件里面的内容
		private List<string> textFile;
		
		public MainForm()
		{
			InitializeComponent();
		}
		
		public void Button1Click(object sender, EventArgs e)
		{
			SaveFileDialog saveFileDialog = new SaveFileDialog();   
			saveFileDialog.Filter="txt文件(*.txt)|*.txt";			
			if(DialogResult.OK == saveFileDialog.ShowDialog()){
				string Name = saveFileDialog.FileName;
				//MessageBox.Show(Name);
				StreamWriter sw = new StreamWriter(Name);
				for(int i = 0; i < result.Count; i  )
					sw.WriteLine(result[i]);
				sw.Close();
			}
		}
		
		private void show(){
			textBox17.Text = "";
			for(int i = 0; i < result.Count; i  ){
				textBox17.AppendText(result[i]   "\r\n");
			}
		}
		
		public void Button2Click(object sender, EventArgs e)
		{
			info = new List<string>();
			foreach (Control ctl in this.groupBox1.Controls){
				if (ctl is TextBox){
					string s = ((TextBox)ctl).Text;
					if(s != "") info.Add(s);
				}
			}
			
			if(!textBox17.Visible){
				textBox17.Location = new Point(288, 12);
				textBox17.Visible = true;
				textBox17.BringToFront();
				button2.Text = "关闭预览";
				button1.Enabled = true;
				// 去重
				result = getResult(info).Distinct().ToList();
				show();
			}
			else{
				textBox17.Visible = false;
				button2.Text = "直接预览";
			}
		}
		
		private List<string> getResult(List<string> list){
			List<string> listall = new List<string>();
			
			for(int i = 0; i < list.Count; i  ){
				for(int j = 0; j < list.Count; j  ){
					if(i != j) listall.Add(info[i]   info[j]);
				}
			}
			
			for(int i = 0; i < info.Count; i  ){
				listall.Add(info[i]);
			}
			
			if(checkBox1.Checked){
				listall.AddRange(getAlways());
			}
			
			if(checkBox6.Checked){
				try{
					listall.AddRange(textFile);
				}
				catch{}
			}
			
			if(checkBox2.Checked) listall = removenum(listall);
			if(checkBox3.Checked) listall = removestring(listall);
			if(checkBox4.Checked){
				try{
					int n = Int32.Parse(textBox27.Text);
					listall = removetooshort(listall, n);
				}
				catch{
					
				}
			}
			if(checkBox5.Checked){
				try{
					int n = Int32.Parse(textBox28.Text);
					listall = removetoolong(listall, n);
				}
				catch{
					
				}
			}
			return listall;
		}
		
		private List<string> removenum(List<string> source){
			List<string> temp = new List<string>();
			for(int i = 0; i < source.Count; i  ){
				if(!Regex.IsMatch(source[i], @"^\d $")) temp.Add(source[i]);
			}
			return temp;
		}
		
		private List<string> removestring(List<string> source){
			List<string> temp = new List<string>();
			for(int i = 0; i < source.Count; i  ){
				if(!Regex.IsMatch(source[i], @"^[a-zA-Z] $")) temp.Add(source[i]);
			}
			return temp;
		}
		
		private List<string> removetoolong(List<string> source, int n){
			List<string> temp = new List<string>();
			for(int i = 0; i < source.Count; i  ){
				if(source[i].Length <= n) temp.Add(source[i]);
			}
			return temp;
		}
		
		private List<string> removetooshort(List<string> source, int n){
			List<string> temp = new List<string>();
			for(int i = 0; i < source.Count; i  ){
				if(source[i].Length >= n) temp.Add(source[i]);
			}
			return temp;
		}
		
		private List<string> getAlways(){
			List<string> temp = new List<string>();
			
			List<string> strs = new List<string>();
			List<string> nums = new List<string>();
			
			// 这个地方可以使左右组合,把这个取消注释就可以了
//			foreach (Control ctl in this.groupBox1.Controls){
//				if (ctl is TextBox){
//					string s = ((TextBox)ctl).Text;
//					if(Regex.IsMatch(s, @"[\d] ")) nums.Add(s);
//				}
//			}
			
			foreach (Control ctl in this.panel1.Controls){
				if (ctl is TextBox){
					string s = ((TextBox)ctl).Text;
					if(Regex.IsMatch(s, @"^\w \d $") || Regex.IsMatch(s, @"^\d \w $")){
						// 分离数字和字符串
						string str = Regex.Replace(s, @"\d", "");
						string num = Regex.Replace(s, @"[^\d]*", "");
						strs.Add(str);
						nums.Add(num);
					}
				}
			}
			
			// 字母处理规则-顺序变更大小写
			int strcount = strs.Count;
			for(int i = 0; i < strcount; i  ){
				string[] tempstr = getStrings(strs[i]);
				for(int j = 0; j < tempstr.Length; j  ){
					strs.Add(tempstr[j]);
					temp.Add(tempstr[j]   nums[i]);
					temp.Add(nums[i]   tempstr[j]);
				}
			}
			
			// 数组规则-截取变化规则
			for(int i = 0; i < strs.Count; i  ){
				for(int j = 0; j < nums.Count; j  ){
					temp.Add(strs[i]   nums[j]);
					temp.Add(nums[j]   strs[i]);
				}
			}
			
			// 字母数字处理规则-字符截取
			int numcount = nums.Count;
			for(int i = 0; i < numcount; i  ){
				string[] tempnum = getNums(nums[i]);
				for(int j = 0; j < tempnum.Length; j  ){
					for(int k = numcount; k < strs.Count; k  ){
						temp.Add(strs[k]   tempnum[j]);
						temp.Add(tempnum[j]   strs[k]);
					}
				}
			}
			
			return temp;
		}
		
		// 字符转大写
		private string[] getStrings(string str){
			char[] ch = str.ToCharArray();
			string[] strs = new string[ch.Length];
			for(int i = 0; i < ch.Length; i  ){
				if(ch[i] >= 'A' && ch[i] <= 'Z') strs[i] = str.Substring(0, i)   (char)(ch[i]   32)   str.Substring(i   1, ch.Length - i - 1);
				if(ch[i] >= 'a' && ch[i] <= 'z') strs[i] = str.Substring(0, i)   (char)(ch[i] - 32)   str.Substring(i   1, ch.Length - i - 1);
			}
			return strs;
		}
		
		//数字截一部分
		private string[] getNums(string str){
			int len = str.Length;
			int num = (int)Math.Pow(2.0, (double)len) - 2;
			char[] ch = str.ToCharArray();
			string[] nums = new string[num];
			for (int i = 1; i < num   1; i  ){
				string temp = "";
				for (int j = 0; j < len; j  ){
					if((i & (1 << j)) != 0) temp  = ch[j];
				}
				nums[i - 1] = temp;
			}
			return nums;
		}
		
		private void TextBox10Click(object sender, EventArgs e)
		{
			OpenFileDialog open = new OpenFileDialog();
			open.Filter = "txt文件(*.txt)|*.txt";
			if(open.ShowDialog() == DialogResult.OK){
				textBox10.Text = open.FileName;
			}
		}
		
		private void Button3Click(object sender, EventArgs e)
		{
			if(!File.Exists(textBox10.Text)){
				MessageBox.Show("文件不存在!");
				return ;
			}
			string line = string.Empty;
			StreamReader sr = new StreamReader(textBox10.Text);
			textFile = new List<string>();
			line = sr.ReadLine();
			textFile.Add(line);
			while(!sr.EndOfStream){
				line = sr.ReadLine();
				textFile.Add(line);
			}
			MessageBox.Show("导入完成!");
			sr.Close();
		}
	}
}