EDN Admin
Well-known member
<pre>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
MatchCollection mc;
Regex r = new Regex("ad|an|av|a|c|dd|dh|do|dv|dw|d|e|h|i|l|k|md|mk|mm|mo|mr|m|nd|nk|nm|nr|nt|nv|nz|n|o|q|ra|rb|re|rk|ro|rs|ry|r|tt|t|v|w|y");
public static string RemoveDigits(string key)
{
return Regex.Replace(key, @"d+.", "");
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open New File";
dlg.InitialDirectory = ("c:\");
dlg.Filter = "Text Files(.txt)|*.txt";
dlg.RestoreDirectory = false;
dlg.FilterIndex = 1;
if (dlg.ShowDialog() == DialogResult.OK)
{
string filename = dlg.FileName;
StreamReader reader = new StreamReader(filename, Encoding.GetEncoding("UTF-8"));
StringBuilder s = new StringBuilder();
while (!reader.EndOfStream)
{
s.AppendLine(reader.ReadLine());
}
reader.Close();
this.richTextBox1.AppendText(s.ToString());
MessageBox.Show("Oqush Tamam!");
}
}
private void button2_Click(object sender, EventArgs e)
{
string input1 = richTextBox1.Text.ToString();
string value1 = RemoveDigits(input1);
string kur = value1.Replace("/", "");
mc = r.Matches(kur);
for (int i = 0; i < mc.Count; i++)
kur = kur.Insert(mc.Index + mc.Value.Length + i, "*");
string[] split = kur.Split(new char[] { * });
for (int i = 0; i < split.Length; i++)
richTextBox2.Text += split + "n";
MessageBox.Show("Tamam!");
}
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = " txt files(*.txt)|*.txt";
dlg.FilterIndex = 2;
dlg.RestoreDirectory = true;
dlg.Title = "Mezmun saqlash";
if (dlg.ShowDialog() == DialogResult.OK && dlg.FileName.Length > 0)
{
StreamWriter myStream = new StreamWriter(dlg.FileName, true);
foreach (string line in richTextBox2.Lines)
{
bool yn = Regex.IsMatch(line, @"nr");
if (yn == true)
{
myStream.Write(line + "t" + "PER" + "rn");
}
else
{
myStream.Write(line + "t" + "O" + "rn");
}
}
myStream.Close();
}
}
}
}
above is the code I wrote, but when I loading big text files, it is hard to display on the textbox because it takes[/code]
<pre>so much time and outofmemory exception,so, I do not want to display the text file on first Richtextbox, and[/code]
<pre>then split it, also not to display on the richtextbox2 after splitting because of time, I just want to have two buttons[/code]
<pre>one is for opening big text file, second one is to remove numbers and dots, split, in the end save the result into [/code]
<pre>text file! please help me to revise the code![/code]
<pre><br/>[/code]
<pre><br/>[/code]
<br/><hr class="sig Will is power!
View the full article
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
MatchCollection mc;
Regex r = new Regex("ad|an|av|a|c|dd|dh|do|dv|dw|d|e|h|i|l|k|md|mk|mm|mo|mr|m|nd|nk|nm|nr|nt|nv|nz|n|o|q|ra|rb|re|rk|ro|rs|ry|r|tt|t|v|w|y");
public static string RemoveDigits(string key)
{
return Regex.Replace(key, @"d+.", "");
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open New File";
dlg.InitialDirectory = ("c:\");
dlg.Filter = "Text Files(.txt)|*.txt";
dlg.RestoreDirectory = false;
dlg.FilterIndex = 1;
if (dlg.ShowDialog() == DialogResult.OK)
{
string filename = dlg.FileName;
StreamReader reader = new StreamReader(filename, Encoding.GetEncoding("UTF-8"));
StringBuilder s = new StringBuilder();
while (!reader.EndOfStream)
{
s.AppendLine(reader.ReadLine());
}
reader.Close();
this.richTextBox1.AppendText(s.ToString());
MessageBox.Show("Oqush Tamam!");
}
}
private void button2_Click(object sender, EventArgs e)
{
string input1 = richTextBox1.Text.ToString();
string value1 = RemoveDigits(input1);
string kur = value1.Replace("/", "");
mc = r.Matches(kur);
for (int i = 0; i < mc.Count; i++)
kur = kur.Insert(mc.Index + mc.Value.Length + i, "*");
string[] split = kur.Split(new char[] { * });
for (int i = 0; i < split.Length; i++)
richTextBox2.Text += split + "n";
MessageBox.Show("Tamam!");
}
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = " txt files(*.txt)|*.txt";
dlg.FilterIndex = 2;
dlg.RestoreDirectory = true;
dlg.Title = "Mezmun saqlash";
if (dlg.ShowDialog() == DialogResult.OK && dlg.FileName.Length > 0)
{
StreamWriter myStream = new StreamWriter(dlg.FileName, true);
foreach (string line in richTextBox2.Lines)
{
bool yn = Regex.IsMatch(line, @"nr");
if (yn == true)
{
myStream.Write(line + "t" + "PER" + "rn");
}
else
{
myStream.Write(line + "t" + "O" + "rn");
}
}
myStream.Close();
}
}
}
}
above is the code I wrote, but when I loading big text files, it is hard to display on the textbox because it takes[/code]
<pre>so much time and outofmemory exception,so, I do not want to display the text file on first Richtextbox, and[/code]
<pre>then split it, also not to display on the richtextbox2 after splitting because of time, I just want to have two buttons[/code]
<pre>one is for opening big text file, second one is to remove numbers and dots, split, in the end save the result into [/code]
<pre>text file! please help me to revise the code![/code]
<pre><br/>[/code]
<pre><br/>[/code]
<br/><hr class="sig Will is power!
View the full article