Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

easy building a string c#

Posted on 2008-06-26
7
Medium Priority
?
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Joel Coehoorn
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 2000 total points
ID: 21878523
sorry copied to much of the date
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

610 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