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
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
andieje
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

        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!
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo