Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

repalce only first match c#

2 views
Skip to first unread message

ShayHk

unread,
Feb 5, 2008, 4:02:33 AM2/5/08
to
Hi All
I Want to know if ther is an easy way to repalce the first match
for exaple :

string input ="xxx @ yyy @ zzz@";
input.repalce("@",1);

the code will repalce all matchs on the string and I want only the
first

Sascha Folville

unread,
Feb 12, 2008, 5:44:28 AM2/12/08
to
Hi ShayHk,

you should identify the first position an then remove the char like
this:

string input = "xxx @ yyy @ zzz@";

int pos = input.IndexOf('@');
if (pos > 0)
{
input = input.Remove(pos, 1);
}

Sascha

0 new messages