how to print particular string in ascending/descending order using arrays?

Posted by Hariinakoti under C# on 8/1/2012 | Points: 10 | Views : 2059 | Status : [Member] | Replies : 1
Hi Friends,
how to print particular string in ascending/descending order using arrays?

ex:my string is RBRBRBRBRB.I want output BBBBRRRR or RRRRBBB like that.
Please solve my problem..

Thanks & Regards
Hari



Responses

Posted by: Megan00 on: 8/2/2012 [Member] Starter | Points: 25

Up
0
Down
Hello, you can use below code to realize it, hope it can help u:
          private void button1_Click(object sender, EventArgs e)

{
string str = this.textBox1.Text.Trim();
char[] chars = str.ToCharArray();
if (chars.Length > 0)
{
for (int i = 0; i < chars.Length; i++)
{
for (int j = 0; j < chars.Length - 1; j++)
{
char temp = chars[j];
if (chars[j] > chars[j + 1])
{
chars[j] = chars[j + 1];
chars[j + 1] = temp;
}
}
}
}
foreach (char c in chars)
this.m_printText += c;
PrintDialog dialog = new PrintDialog();
PrintDocument doc = new PrintDocument();
doc.PrintPage+=new PrintPageEventHandler(doc_PrintPage);
dialog.AllowPrintToFile = true;
dialog.Document = doc;
if (dialog.ShowDialog() == DialogResult.OK)
doc.Print();
}
protected void doc_PrintPage(Object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString(this.m_printText,new System.Drawing.Font ("Arial",10,FontStyle.Regular),Brushes.Black,new System.Drawing.PointF(20,20));
e.HasMorePages = false;

}


Never give up! Smile to the world!
http://excelcsharp.blog.com/

Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response