1. 程式人生 > >解決撰寫畢業論文時知網空格處理與中英字串轉化

解決撰寫畢業論文時知網空格處理與中英字串轉化

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) { } } }

設計介面

百度雲下載連結:
一個處理直接從知網複製論文出現的空格,中英字元轉化的小軟體