add space in string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NuCoder

    add space in string

    I'm getting a string like this

    BMWLEXUSBMWMERC EDES
    how can I add a space so it looks like this

    BMW, LEXUS, BMW, MERCEDES




  • Jon Skeet [C# MVP]

    #2
    Re: add space in string

    NuCoder <me@me.com> wrote:[color=blue]
    > I'm getting a string like this
    >
    > BMWLEXUSBMWMERC EDES
    > how can I add a space so it looks like this
    >
    > BMW, LEXUS, BMW, MERCEDES[/color]

    Well, you'll have to know what to split the string on first - do you
    have a predefined list of tokens that the string will be comprised of?

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • NuCoder

      #3
      Re: add space in string

      unfortuneally no, it can be in any order at any given time, so I don't have
      any predefined list.


      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1d1c22 e534468ee998c32 c@msnews.micros oft.com...[color=blue]
      > NuCoder <me@me.com> wrote:[color=green]
      >> I'm getting a string like this
      >>
      >> BMWLEXUSBMWMERC EDES
      >> how can I add a space so it looks like this
      >>
      >> BMW, LEXUS, BMW, MERCEDES[/color]
      >
      > Well, you'll have to know what to split the string on first - do you
      > have a predefined list of tokens that the string will be comprised of?
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • John B

        #4
        Re: add space in string

        NuCoder wrote:[color=blue]
        > unfortuneally no, it can be in any order at any given time, so I don't have
        > any predefined list.
        >[/color]
        The order may be variable but you _will_ have to have some sort of list
        that defines the words you wish to separate.

        string[] Cars = new string[3]{"BMW", "LEXUS", "MERCEDES"} ;

        After that, say you have an array of strings containing your words, you
        can do:

        string FullString = "BMWLEXUSBMWMER CEDES";
        foreach(string Car in Cars)
        {
        FullString = FullString.Repl ace(Car, Car + ", ");
        }

        JB
        [color=blue]
        >
        > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
        > news:MPG.1d1c22 e534468ee998c32 c@msnews.micros oft.com...
        >[color=green]
        >>NuCoder <me@me.com> wrote:
        >>[color=darkred]
        >>>I'm getting a string like this
        >>>
        >>>BMWLEXUSBMWM ERCEDES
        >>>how can I add a space so it looks like this
        >>>
        >>>BMW, LEXUS, BMW, MERCEDES[/color]
        >>
        >>Well, you'll have to know what to split the string on first - do you
        >>have a predefined list of tokens that the string will be comprised of?
        >>
        >>--
        >>Jon Skeet - <skeet@pobox.co m>
        >>http://www.pobox.com/~skeet
        >>If replying to the group, please do not mail me too[/color]
        >
        >
        >[/color]

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: add space in string

          NuCoder <me@me.com> wrote:[color=blue]
          > unfortuneally no, it can be in any order at any given time, so I don't have
          > any predefined list.[/color]

          In that case there's no correct answer. For instance, what should the
          following be split as:

          AKJHASDLASDJKHK AJSHDKJHALXACAD HKCIDQTOUO

          ?

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          Working...