Find last comma in string

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

    #1

    Find last comma in string

    Hello,

    I need to replace the last comma in a string by " and ". How can I do
    this?

    Thanks,
    Miguel
  • Peter Duniho

    #2
    Re: Find last comma in string

    On Fri, 21 Nov 2008 15:57:26 -0800, shapper <mdmoura@gmail. comwrote:
    Hello,
    >
    I need to replace the last comma in a string by " and ". How can I do
    this?
    http://msdn.microsoft.com/en-us/libr...stindexof.aspx

    That link will help you solve the first half of the problem. I leave it
    as an exercise for you to solve the second half, but I'll provide a hint:
    generally speaking, if you want to know what you can do with an instance
    of String, you should look at the "Class Members" documentation page on
    MSDN. Often you will find that there is already method to accomplish your
    goal or, at the very least, one that would be helpful.

    You could have answered the first half of this question by using that
    hint, and you should be able to answer the second half by doing so as well.

    Pete

    Comment

    • Mark Rae [MVP]

      #3
      Re: Find last comma in string

      "shapper" <mdmoura@gmail. comwrote in message
      news:df9dc6f8-44d7-4b1b-8773-1e37cf197310@33 g2000yqm.google groups.com...
      I need to replace the last comma in a string by " and ". How can I do
      this?
      http://msdn.microsoft.com/en-us/libr...stindexof.aspx
      http://msdn.microsoft.com/en-us/library/aka44szs.aspx
      http://msdn.microsoft.com/en-us/libr...g.replace.aspx


      --
      Mark Rae
      ASP.NET MVP


      Comment

      • Family Tree Mike

        #4
        Re: Find last comma in string

        "shapper" <mdmoura@gmail. comwrote in message
        news:df9dc6f8-44d7-4b1b-8773-1e37cf197310@33 g2000yqm.google groups.com...
        Hello,
        >
        I need to replace the last comma in a string by " and ". How can I do
        this?
        >
        Thanks,
        Miguel

        Does your list potentially contain currency strings? If so, I hope that one
        of your test strings is "$3,000.00, $4,000.00, $5,000.00".

        Comment

        Working...