'saving text from txt in a list or variable and extracting words with "S" load it to another file and send in a e mail
I'm making a windows form in C# that would allow me to load a text from a text file, extract only the words that have a "S", load these words in another text file, separate these words with ";", and finally send this new file through an email. So far, I have managed to read the file and print the text on screen, but how do I save the text in a variable (for instance "a") so I can then use regex to extract the words with "S" and then send them in a email?
Here is a sample of the text:
The Snowman It was nearly Christmas. Katie woke up and found that the world was white and magical.
- Snow, she shouted, snow for Christmas.
And here is the code for the form:
namespace Lectura_y_escritura
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
StreamWriter escritura = new StreamWriter(@"C:\Users\Joséguillermo\Desktop\C#\Texto.txt",true);
try
{
escritura.WriteLine("\n");
escritura.WriteLine(" " + textBox1.Text);
escritura.WriteLine("\n");
}
catch {
MessageBox.Show("Error de escritura");
}
escritura.Close();
}
private void button1_Click(object sender, EventArgs e)
{
List<string> texto = new List<string>();
StreamReader lectura = new StreamReader(@"C:\Users\Joséguillermo\Desktop\C#\Texto.txt", true) ;
string linea;
try
{
linea = lectura.ReadLine();
while (linea != null)
{
richTextBox1.AppendText(linea + "\n");
linea = lectura.ReadLine();
texto.Add(linea);
}
foreach (string j in texto)
{
Console.WriteLine(j);
}
}
catch {
MessageBox.Show("Error de lectura");
}
lectura.Close();
}
private void button4_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
string pattern = @"\b[Ss]\b";
}
}
}
and here is the form (or a photo of it)
I really apreciate any help i could get since i have no experience in c#.
Thanks in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
