Reputation: 387
I'm looking for a way to take each item in a rich text box that a user can customize and take those items and put them into a different text box with a string attatched.
for example: the richtextbox would contain and be separated like this:
Sad
Glad
Mad
The string i want those to go into is: John was ____ today.
id like it to output all 3 on different lines but in a the same textbox (different from the richtextbox).
John was Sad today.
John was Glad today.
John was Mad today.
This is all simplified to make it easier to understand, i have been pulling my hair out trying to get it to work.
Thanks in advance.
Upvotes: 0
Views: 1243
Reputation: 53593
Remember that the Text in a RichTextBox control is an array of strings with each line an element in the array, so what you can do is iterate through this array and contruct your sentences with each pass.
const string StringTemplate = "John was {0} today.";
...
var sb = new StringBuilder();
foreach (var line in richTextBox1.Lines) {
sb.AppendLine(string.Format(StringTemplate, line));
}
textBox1.Text = sb.ToString();
Upvotes: 3