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.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Mar 29, 2011, 5:08 AM
foreach(string s in str.Split(' ')) Console.WriteLine(s);
CrishPosted Mar 29, 2011, 1:45 AM
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;
FroglegPosted Mar 29, 2011, 1:28 AM
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;
}
}
}