Reputation: 55247
I have a SQL Server database (service-based) with a table (Contact). Instead of having multiple tables, I decided to have one delimited string called Emails. So how could I use a Regex and a delimiter to add on to the string.
Upvotes: 0
Views: 236
Reputation: 700680
First of all, you should consider to change your decision to have delimited values instead of an extra table. It may seem simpler at first, but as you have already noticed, it quickly gets painful to work with.
That said, there are some different ways to handle delimited values, but using a regular expression is hardly one of them.
For example:
if (value.Length == 0) {
value = email;
} else {
value = value + delimiter + email;
}
Or:
List<string> emails = new List(value.Split(new String[]{ delimiter }));
emails.Add(email);
value = String.Join(delimiter, emails.ToArray());
Upvotes: 3