excuse me, i'm trying to make simple application which converting the words into word. for example
Enable = able Payment = Pay
the text on my notepad was "enable payment"
i'm using 2 sample words above, and i'm not getting what i need. i wrote "enable" and "payment" on notepad.txt. then the application will start and get the word.
and the application will start trimming the words cut the "En" and "ment" so their result will be "able" and "pay"
my application can trim the single word "enable" to "able" . and "payment" to "pay" but, the application didn't work well if i write 2 words or more such as "enable payment" or "payment enable"
here is the user interface image
and here is the source code,
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;
namespace KTM'
{
public partial class KTM : Form
{
public string notepad;
public KTM()
{
InitializeComponent();
textBox1.Enabled=false;
button2.Enabled = false;
button3.Enabled = false;
}
void enable()
{
button2.Enabled = true;
button3.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
string dir = Application.StartupPath.ToString();
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Open *txt files";
fdlg.InitialDirectory = @dir;
fdlg.Filter = "Text files (*.txt)|*.txt|Text Files (*.txt)|*.txt";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fdlg.FileName;
}
else
{
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Equals(""))
{
}
else
{
enable();
}
}
private void button2_Click(object sender, EventArgs e)
{
notepad = textBox1.Text;
StreamReader sr = new StreamReader(notepad);
string paragraf = sr.ReadToEnd();
sr.Close();
string[] kata = paragraf.Split(' ');
int i = 0;
//MessageBox.Show(kata[0]+" "+kata[1]+" "+kata[2]);
foreach (string ambil in kata)
{
if (kata[i].StartsWith("en"))
{
kata[i] = kata[i].Substring(2);
}
if(kata[i].EndsWith("ment"))
{
int len = kata[i].Length;
int kepake = len - 4;
kata[i] = kata[i].Substring(0, kepake);
}
}
i++;
StreamWriter sw = new StreamWriter(notepad);
i = 0;
foreach (string ambil in kata)
{
sw.Write(kata[i]+" ");
}
i++;
sw.Flush();
sw.Close();
MessageBox.Show("Converted and Saved ","KTM Stemming",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
private void button3_Click(object sender, EventArgs e)
{
notepad = textBox1.Text;
System.Diagnostics.Process.Start(notepad);
}
}
}
foreach (string ambil in kata)
{
if (kata[i].StartsWith("en"))
{
kata[i] = kata[i].Substring(2);
}
if(kata[i].EndsWith("ment"))
{
int len = kata[i].Length;
int kepake = len - 4;
kata[i] = kata[i].Substring(0, kepake);
}
}
this is part of your problem as it is a foreach but you are using it like a for loop. you probably want for (int i=0; i<kata.Length; i++)
also you are writting to a file outside of your for loop, so either you need to put your writing in that for loop, or make another for loop.