Suppose, we have a string str = "This is a Text Book"
Now, we need to print each substring(individually) of str as :
This
is
a
Text
Book
Please anyone write a code snippet to do so.
How to print each substring of a string ?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.


FroglegRank #1,020 · 1.9K reputationPosted Mar 28, 2011, 9:28 PM EDT
public partial class Form1 : Form
{
string[] mystring;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
mystring = textBox1.Text.Split(' ');
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int count = 20;
foreach (string str in mystring)
{
e.Graphics.DrawString(str, textBox1.Font, Brushes.Black, 20, count);
count = count + 15;
}
}
}
CrishRank #1,487 · 1.1K reputationPosted Mar 28, 2011, 9:45 PM EDT
write string str = "This is a Text Book".Split(' ');
response.write str
or
string str = "This is a Text Book".Split("\n");
response.write str;
VulpesRank #55 · 29.2K reputationPosted Mar 29, 2011, 1:08 AM EDT
foreach(string s in str.Split(' ')) Console.WriteLine(s);