Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Forms1
- {
- public partial class Form2 : Form
- {
- FileStream fileStream;
- Byte[] dataBytes;
- string fileName;
- public Form2()
- {
- InitializeComponent();
- }
- private void SaveButton_Click(object sender, EventArgs e)
- {
- if (richTextBox1.Text.Length > 0)
- {
- fileStream = new FileStream(fileName, FileMode.OpenOrCreate);
- dataBytes = Encoding.ASCII.GetBytes(richTextBox1.Text);
- fileStream.Write(dataBytes, 0, dataBytes.Length);
- fileStream.Close();
- }
- }
- private void OpenButton_Click(object sender, EventArgs e)
- {
- try
- {
- StreamReader streamReader;
- string line;
- OpenFileDialog opf = new OpenFileDialog();
- opf.Title = "select file to open";
- opf.Filter = "TXT document|*.txt";
- if (opf.ShowDialog() == DialogResult.OK)
- {
- richTextBox1.Text = "";
- streamReader = new StreamReader(opf.FileName);
- line = streamReader.ReadToEnd();
- richTextBox1.Text = line;
- streamReader.Close();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("error reading file: " + ex.StackTrace);
- }
- }
- private void AppendButton_Click(object sender, EventArgs e)
- {
- if (richTextBox1.Text.Length > 0)
- {
- SaveFileDialog sfdiag = new SaveFileDialog();
- sfdiag.Title = "Select file destination";
- sfdiag.Filter = "TXT document|* .txt";
- if (sfdiag.ShowDialog() == DialogResult.OK)
- {
- fileStream = new FileStream(sfdiag.FileName, FileMode.Append);
- dataBytes = Encoding.ASCII.GetBytes(richTextBox1.Text);
- fileStream.Write(dataBytes, 0, dataBytes.Length);
- fileStream.Close();
- }
- }
- }
- private void SplitButton_Click(object sender, EventArgs e)
- {
- string text;
- string[] words;
- string splitSym = Microsoft.VisualBasic.Interaction.InputBox("Split symbol");
- if (richTextBox1.Text.Length > 0)
- {
- text = richTextBox1.Text;
- words = text.Split(splitSym[0]);
- richTextBox1.Text = "";
- foreach (string item in words)
- {
- richTextBox1.Text += item + Environment.NewLine;
- }
- }
- }
- private void SubstringButton_Click(object sender, EventArgs e)
- {
- string text;
- string nuo = Microsoft.VisualBasic.Interaction.InputBox("nuo");
- string iki = Microsoft.VisualBasic.Interaction.InputBox("iki");
- if (richTextBox1.Text.Length > Convert.ToInt32(iki))
- {
- text = richTextBox1.Text;
- richTextBox1.Text = "";
- richTextBox1.Text = text.Substring(Convert.ToInt32(nuo), Convert.ToInt32(iki));
- }
- }
- private void SearchButton_Click(object sender, EventArgs e)
- {
- string text;
- if (richTextBox1.Text.Length > 0)
- {
- text = richTextBox1.Text;
- string ats = Microsoft.VisualBasic.Interaction.InputBox("Iveskit teksta kurio ieskosite");
- if (text.Contains(ats))
- {
- int pos = text.IndexOf(ats);
- richTextBox1.Focus();
- richTextBox1.Select(pos, ats.Length);
- }
- else
- {
- MessageBox.Show("Ieškomos frazės nėra");
- }
- }
- }
- private void ReplaceButton_Click(object sender, EventArgs e)
- {
- string rplc, text;
- if (richTextBox1.Text.Length > 0)
- {
- text = richTextBox1.Text;
- string replText = Microsoft.VisualBasic.Interaction.InputBox("Iveskite teksta kuri replace'nsit");
- if (text.Contains(replText))
- {
- rplc = Microsoft.VisualBasic.Interaction.InputBox("Iveskite nauja teksta");
- richTextBox1.Text = richTextBox1.Text.Replace(replText, rplc);
- }
- else
- {
- MessageBox.Show("Nera tokio teksto");
- }
- }
- }
- public void newTextFile(string file)
- {
- file = fileName;
- try
- {
- StreamReader streamReader;
- string line;
- richTextBox1.Text = "";
- streamReader = new StreamReader(fileName);
- line = streamReader.ReadToEnd();
- richTextBox1.Text = line;
- streamReader.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error reading file: " + ex.StackTrace);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement