Link to home
Start Free TrialLog in
Avatar of andieje
andieje

asked on

how to replace the last comma in a comma separated list with ' and '

Hi

I am using vb.net 2005 and I'm not very familiar with regular expressions.

If i had a comma separated list of items in a string, how would i locate the last comma in the list and replace it with ' and '

for example

me, you becomes me and you
me, you, barbara becomes me, you and barbara

thanks a lot
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
        Dim str As String = "me, you, barbara"
        Dim index as integer = str.LastIndexOf(","c)
        str = str.Substring(0, index) & " and" & str.Substring(index + 1)

Open in new window

Avatar of andieje
andieje

ASKER

thanks!