Insert a character in a string

Discussion in 'General Computer Support' started by madmars, Feb 7, 2011.

  1. madmars

    madmars

    Joined:
    Feb 7, 2011
    Messages:
    1
    Hi!
    Lets say I have a string with numbers "123456789". How can I insert commas to the string to make it look like this "123,456,789"?I want to do this in C and i've tried all kind of methods but i did'n manage to do it.
    Can anyone help me please?

    Marius
    madmars, Feb 7, 2011
    #1
    1. Advertising

  2. madmars

    MichelM

    Joined:
    Feb 24, 2011
    Messages:
    1
    Hi Marius,

    There's a nice example on C# station, mentioning the split() and join() methods, you'll be needing join(), unless you've already been using it.

    This first two parts should be useful for you:

    Code:
    using System;
    
    namespace csharp_station.howto
    {
        class StringJoinSplit
        {
            static void Main(string[] args)
            {
                // comma delimited string
                string commaDelimited = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
    
                Console.WriteLine("Original Comma Delimited String: \n{0}\n", commaDelimited);
    
                // separate individual items between commas
                string[] year = commaDelimited.Split(new char[] {','});
    
                Console.WriteLine("Each individual item: ");
    
                foreach(string month in year)
                {
                    Console.Write("{0} ", month);
                }
                Console.WriteLine("\n");
    
            }
        }
    } 
    
    And here's the output:

    Original Comma Delimited String:
    Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec

    Each individual item:
    Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

    HTH,

    Michel
    Last edited: Feb 24, 2011
    MichelM, Feb 24, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RObErT_RaTh

    Modding a character LCD?

    RObErT_RaTh, Aug 24, 2005, in forum: Case Modding
    Replies:
    19
    Views:
    3,483
    unholy
    Sep 1, 2005
  2. RObErT_RaTh

    My Character LCD Module [UPDATED 30/8]

    RObErT_RaTh, Aug 29, 2005, in forum: Case Modding
    Replies:
    6
    Views:
    2,643
    unholy
    Sep 1, 2005
  3. RObErT_RaTh

    Guide: Character LCD Module

    RObErT_RaTh, Aug 31, 2005, in forum: Case Modding
    Replies:
    2
    Views:
    6,008
    RObErT_RaTh
    Sep 1, 2005
  4. Gary G. Taylor

    Re: Insert Form Feed Character in Email Message

    Gary G. Taylor, Jul 16, 2003, in forum: Computer Support
    Replies:
    0
    Views:
    576
    Gary G. Taylor
    Jul 16, 2003
  5. newasp.net
    Replies:
    1
    Views:
    1,581
    imransyed63
    Aug 21, 2008
Loading...

Share This Page