开发者

Use a Regex to form delimited string for SQL Server

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 co开发者_运维技巧uld I use a Regex and a delimiter to add on to the string.


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());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜