比较字符串
https://p-blog.csdn.net/images/p_blog_csdn_net/wgsnet/EntryImages/20080926/CompareString.png
//*****************************************
Form1.Designer.cs
******************************************/
namespace CompareString
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.TBresult = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.TBSplit = new System.Windows.Forms.TextBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(410, 329);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 60);
this.button1.TabIndex = 0;
this.button1.Text = "Compare";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 12);
this.textBox1.MaxLength = 927678888;
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBox1.Size = new System.Drawing.Size(384, 368);
this.textBox1.TabIndex = 1;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(500, 21);
this.textBox2.MaxLength = 927678888;
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBox2.Size = new System.Drawing.Size(384, 368);
this.textBox2.TabIndex = 2;
//
// TBresult
//
this.TBresult.Location = new System.Drawing.Point(12, 396);
this.TBresult.MaxLength = 927678888;
this.TBresult.Multiline = true;
this.TBresult.Name = "TBresult";
this.TBresult.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.TBresult.Size = new System.Drawing.Size(872, 191);
this.TBresult.TabIndex = 3;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.TBSplit);
this.groupBox1.Controls.Add(this.checkBox1);
this.groupBox1.Location = new System.Drawing.Point(405, 248);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(85, 75);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
//
// TBSplit
//
this.TBSplit.Location = new System.Drawing.Point(5, 46);
this.TBSplit.Name = "TBSplit";
this.TBSplit.Size = new System.Drawing.Size(74, 20);
this.TBSplit.TabIndex = 7;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(6, 19);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(61, 17);
this.checkBox1.TabIndex = 6;
this.checkBox1.Text = "Split By";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(896, 599);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.TBresult);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "CompareString By wgscd QQ:153964481 比较左右两边字符串";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox TBresult;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox TBSplit;
private System.Windows.Forms.CheckBox checkBox1;
}
}
//*****************************************
Form1.cs
******************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CompareString
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
checkBox1.Checked = false;
TBSplit.Enabled = false;
}
string result;
string str1;
string str2;
private void button1_Click(object sender, EventArgs e)
{
result = "";
TBresult.Text = "";
str1=textBox1.Text;
str2 = textBox2.Text;
if (str1.IndexOf(TBSplit.Text)<0){
TBresult.Text = "Please check the Split chars !";
return;
}
if (checkBox1.Checked && TBSplit.Text != "")
{
string[] strs1 = str1.Split(TBSplit.Text.ToCharArray());
for (int i = 0; i < strs1.Length; i++)
{
if (str2.IndexOf(strs1[i]) < 0)
{
result += strs1[i] + " Not In The Right Part !/r/n";
}
}
result += "********************************************************************************/r/n";
string[] strs2 = str2.Split(TBSplit.Text.ToCharArray());
for (int i = 0; i < strs2.Length; i++)
{
if (str1.IndexOf(strs2[i]) < 0)
{
result += strs2[i] + " Not In The Left Part !/r/n";
}
}
}
else {
string CRLF = "/r/n";
string[] strs1 = str1.Split(CRLF.ToCharArray());
for (int i = 0; i < strs1.Length; i++)
{
if (str2.IndexOf(strs1[i]) < 0)
{
result += strs1[i] + " Not In The Right Part !/r/n";
}
}
result += "********************************************************************************/r/n";
string[] strs2 = str2.Split(CRLF.ToCharArray());
for (int i = 0; i < strs2.Length; i++)
{
if (str1.IndexOf(strs2[i]) < 0)
{
result += strs2[i] + " Not In The Left Part !/r/n";
}
}
}
TBresult.Text = result;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
TBSplit.Enabled = checkBox1.Checked;
}
}
}
//*****************************************
Program.cs
******************************************/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace CompareString
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}