解决撰写毕业论文时知网空格处理与中英字符串转化

时间:2023-02-15 06:35:36
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Trim
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void richTextBox1_TextChanged(object sender, EventArgs e)
{
// richTextBox1.BackColor = Color.Green;
}

private void 转化_Click(object sender, EventArgs e)
{
string strWrite = string.Empty;
string strRead = richTextBox1.Text;
CharEnumerator CEnumerator = strRead.GetEnumerator();

while (CEnumerator.MoveNext())
{
byte[] array = new byte[1];
array = System.Text.ASCIIEncoding.ASCII.GetBytes(CEnumerator.Current.ToString());
int asciicode = (short)(array[0]);
if (asciicode != 32)
{
strWrite += CEnumerator.Current.ToString();
}
}
richTextBox2.Text = strWrite;
//Console 输出字符串
}

private void button1_Click(object sender, EventArgs e)
{
string strWrite = string.Empty;
string strRead = richTextBox1.Text;
CharEnumerator CEnumerator = strRead.GetEnumerator();

while (CEnumerator.MoveNext())
{
byte[] array = new byte[1];
array = System.Text.ASCIIEncoding.ASCII.GetBytes(CEnumerator.Current.ToString());
int asciicode = (short)(array[0]);
if (asciicode != 32)
{
strWrite += CEnumerator.Current.ToString();
}
}
//Console 输出字符串
string l_strResult = strWrite.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
richTextBox2.Text = l_strResult;
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void 转化ToolStripMenuItem_Click(object sender, EventArgs e)
{
string strWrite = string.Empty;
string strRead = richTextBox1.Text;
CharEnumerator CEnumerator = strRead.GetEnumerator();

while (CEnumerator.MoveNext())
{
byte[] array = new byte[1];
array = System.Text.ASCIIEncoding.ASCII.GetBytes(CEnumerator.Current.ToString());
int asciicode = (short)(array[0]);
if (asciicode != 32)
{
strWrite += CEnumerator.Current.ToString();
}
}
richTextBox2.Text = strWrite;
//richTextBox2.Copy();
//richTextBox2.Paste();

}

private void 打开文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
openFileDialog1.Filter = "";
openFileDialog1.ShowDialog();
//textBox1.Text = openFileDialog1.FileName;
StreamReader sreader = new StreamReader(openFileDialog1.FileName, Encoding.Default);
//openFileDialog1.
// if (Directory.Exists(openFileDialog1.FileName))
// {
richTextBox1.Text = sreader.ReadToEnd();
sreader.Close();
// }
// else
// {
// MessageBox.Show("输入文件名不能为空");
//}
}
catch (FormatException)
{
return;
}

}

private void 保存文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
string character=richTextBox2.Text;
StreamWriter myStream;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
myStream = new StreamWriter(saveFileDialog1.FileName);
myStream.Write(richTextBox2.Text);
// Code to write the stream goes here.
myStream.Close();
}
}

private void 清空所有文本ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
richTextBox2.Clear();
}

private void 复制结果ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (richTextBox2.Text.Trim() == String.Empty)
{
MessageBox.Show("孬孬提示:没有要粘贴的内容!");
}
else
Clipboard.SetText(richTextBox2.Text);
}

private void 符号处理ToolStripMenuItem_Click(object sender, EventArgs e)
{
string strWrite = string.Empty;
string strRead = richTextBox1.Text;
CharEnumerator CEnumerator = strRead.GetEnumerator();

while (CEnumerator.MoveNext())
{
byte[] array = new byte[1];
array = System.Text.ASCIIEncoding.ASCII.GetBytes(CEnumerator.Current.ToString());
int asciicode = (short)(array[0]);
if (asciicode != 32)
{
strWrite += CEnumerator.Current.ToString();
}
}
//Console 输出字符串
string l_strResult = strWrite.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace(".", "。").Replace(",",",");

richTextBox2.Text = l_strResult;
//richTextBox2.Copy();

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确定萌萌的关闭文字处理小助手么?", "确定离开", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
e.Cancel = true;
}
}

private void Form1_DoubleClick(object sender, EventArgs e)
{
MessageBox.Show("别点啦");
}

private void Form1_MouseEnter(object sender, EventArgs e)
{

}
}
}

百度云下载链接:
一个处理直接从知网复制论文出现的空格,中英字符转化的小软件