Hi. I would like to know the steps to make the text (automatically) of the fifth word in any given sentence (assuming sentences have more than five or more words) to be in italic form by counting characters or strings (making the first character as the starting point). I have no knowledge about programming, please explain the steps in layman's terms. Thanks.
Loading
FroglegPosted Jun 8, 2011, 12:36 AM
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
loadTxt();
}
public void loadTxt()
{
richTextBox1.Text = "change the chars to italic so the chars to are not regular";
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Select(richTextBox1.Text.IndexOf("italic"), "italic".Length);
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Italic);
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.SelectionLength = 0;
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.SaveFile("test.rtf");
}
private void button3_Click(object sender, EventArgs e)
{
richTextBox1.Text = string.Empty;
richTextBox1.LoadFile("test.rtf");
}
private void button4_Click(object sender, EventArgs e)
{
richTextBox1.Text = string.Empty;
}
private void button5_Click(object sender, EventArgs e)
{
string[] str = richTextBox1.Text.Split(' ');
int count = 1;
foreach ( string s in str)
{
if (count==5)
{
richTextBox1.Select(richTextBox1.Text.IndexOf(s), s.Length);
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Italic);
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.SelectionLength = 0;
count = 0;
}
count++;
}
}
}
Sam HobbsPosted Jun 7, 2011, 10:44 PM
Sam HobbsPosted Jun 7, 2011, 10:39 PM
FroglegPosted Jun 7, 2011, 4:34 PM
namespace FifthWord
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
loadTxt();
}
public void loadTxt()
{
richTextBox1.Text = "change the chars to italic";
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Select(richTextBox1.Text.IndexOf("italic"), "italic".Length);
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Italic);
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.SelectionLength = 0;
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.SaveFile("test.rtf");
}
private void button3_Click(object sender, EventArgs e)
{
richTextBox1.Text = string.Empty;
richTextBox1.LoadFile("test.rtf");
}
private void button4_Click(object sender, EventArgs e)
{
richTextBox1.Text = string.Empty;
}
}
}