Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 821721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:41:11+00:00 2026-05-15T02:41:11+00:00

Is there a cool way to take something like this: Customer Name – City,

  • 0

Is there a cool way to take something like this:

Customer Name - City, State - ID
Bob Whiley - Howesville, TN - 322
Marley Winchester - Old Towne, CA - 5653

and format it to something like this:

Customer Name     - City,       State - ID
Bob Whiley        - Howesville, TN    - 322
Marley Winchester - Old Towne,  CA    - 5653

Using string format commands?

I am not too hung up on what to do if one is very long. For example this would be ok by me:

Customer Name     - City,       State - ID
Bob Whiley        - Howesville, TN    - 322
Marley Winchester - Old Towne,  CA    - 5653
Super Town person - Long Town Name, WA- 45648 

To provide some context. I have a drop down box that shows info very similar to this. Right now my code to create the item in the drop down looks like this:

public partial class CustomerDataContract
{
    public string DropDownDisplay
    {
        get
        {
             return  Name + " - " + City + ",  " + State + " - " + ID;
        }
    }
}

I am looking for a way to format this better. Any ideas?


This is what I ended up with:

HttpContext.Current.Server.HtmlDecode(
    String.Format("{0,-27} - {1,-15}, {2, 2} - {3,5}", 
    Name, City, State, ID)
    .Replace(" ", " "));

The HtmlDecode changes the   to a space that can withstand the space removing formatting of the dropdown list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:41:12+00:00Added an answer on May 15, 2026 at 2:41 am

    You can specify the number of columns occupied by the text as well as alignment using Console.WriteLine or using String.Format:

    // Prints "--123       --"
    Console.WriteLine("--{0,-10}--", 123);
    // Prints "--       123--"
    Console.WriteLine("--{0,10}--", 123);
    

    The number specifies the number of columns you want to use and the sign specifies alignment (- for left alignment, + for right alignment). So, if you know the number of columns available, you could write for example something like this:

    public string DropDownDisplay { 
      get { 
        return String.Format("{0,-10} - {1,-10}, {2, 10} - {3,5}"),
          Name, City, State, ID);
      } 
    } 
    

    If you’d like to calculate the number of columns based on the entire list (e.g. the longest name), then you’ll need to get that number in advance and pass it as a parameter to your DropDownDisplay – there is no way to do this automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best way of doing this: mail = bob@something.com mail2 = mail.do_magic #
So there's this new cool thing, these NoSQL-databases. And so there's my data: Rows
There's this cool new feature in SP 2010 where you can specify a custom
I found out a cool way to preload a flash in this page http://www.riacodes.com/flash/basic-flash-preloader/
Is there a way to take a List and convert it into a comma
In jQuery, is there another way to write this? Version 1 $(#date_filter-enable).click(function() { $(#search_dates).removeClass(hidden);
Possible Duplicate: New Cool Features of C# 4.0 Hello, There are several(many) questions at
There seems to be a similar question to this on here but with the
There are many conflicting statements around. What is the best way to get the
I have a file that contains filenames like this: my_cool_file.xxx my_cool_file2.xxx my_cool_file3.xxx I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.