Solved

easy building a string c#

Posted on 2008-06-26
7
230 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
ID: 21878328
i would use a StringBuilder under the System.Text namespace
0
 
LVL 18

Expert Comment

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

Expert Comment

by:burakiewicz
ID: 21878405
       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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 16

Expert Comment

by:burakiewicz
ID: 21878414
date compliments of j
0
 

Author Comment

by:mathieu_cupryk
ID: 21878489
              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
ID: 21878497
 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
ID: 21878523
sorry copied to much of the date
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Simple Injector with Web Service 4 44
2 questions 10 25
Service Controller 1 23
REXEX help Part 2 2 25
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

831 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