Solved

easy building a string c#

Posted on 2008-06-26
7
212 Views
Last Modified: 2013-12-16
string FileName = "";
                string Pools = "";
                if (chkboxWheat.Checked)
                    Pools = "Wheat ";
                if (chkboxDurum.Checked)
                    Pools += "Durum ";
                if (chkboxBarley.Checked)
                    Pools += "Barley ";
                if (chkboxDesBarley.Checked)
                    Pools += "Des Barley ";
                FileName = dr["PRICE_LIST_HDR_ID"] + " " + dr["LOAD_TYPE_NAME"] + Pools + " " + System.DateTime.Now + " " + ".xls";

I am not sure if there is a better way to concate the Pools.
Also for System.DateTime I need July 2 for example.
0
Comment
Question by:mathieu_cupryk
  • 4
  • 2
7 Comments
 
LVL 16

Expert Comment

by:burakiewicz
Comment Utility
i would use a StringBuilder under the System.Text namespace
0
 
LVL 18

Expert Comment

by:jcoehoorn
Comment Utility
And to get the date format you want:
System.DateTime.Now.ToString("MMMM d");
0
 
LVL 16

Expert Comment

by:burakiewicz
Comment Utility
       System.Text.StringBuilder sb = new System.Text.StringBuilder();
        string FileName = "";
        if (chkboxWheat.Checked)
            sb.Append("Wheat ");
        if (chkboxDurum.Checked)
            sb.Append("Durum ");
        if (chkboxBarley.Checked)
            sb.Append("Barley ");
        if (chkboxDesBarley.Checked)
            sb.Append("Des Barley ");
        FileName = string.Concat(dr["PRICE_LIST_HDR_ID"], " ", dr["LOAD_TYPE_NAME"],
                    sb.ToString(), " ", System.DateTime.Now.ToString("MMMM d");" ", ".xls");
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:burakiewicz
Comment Utility
date compliments of j
0
 

Author Comment

by:mathieu_cupryk
Comment Utility
              FileName = string.Concat(dr["PRICE_LIST_HDR_ID"], " ", dr["LOAD_TYPE_NAME"], sb.ToString(), " ", System.DateTime.Now.ToString("MMMM d");" ", ".xls");

there is an error in this string.
0
 

Author Comment

by:mathieu_cupryk
Comment Utility
 FileName = string.Concat(dr["PRICE_LIST_HDR_ID"].ToString(), " ", dr["LOAD_TYPE_NAME"].ToString(), sb.ToString(), " ", System.DateTime.Now.ToString("MMMM d"), " ", ".xls");      
             
0
 
LVL 16

Accepted Solution

by:
burakiewicz earned 500 total points
Comment Utility
sorry copied to much of the date
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now