从字符串数组中删除项目 [英] Remove item from string array

查看:63
本文介绍了从字符串数组中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库字段,其中包含以下数据:

I have a database field with data such as this:

76,60,12

例如,如果我要删除60,该怎么办?

If I want to remove, for example, 60, what do I have to do?

要删除的号码可以在任何地方.如果需要,我还需要删除逗号.

The number to be removed could be any place. I also need to remove the comma, if needed.

我正在使用.NET 2.0.

I'm using .NET 2.0.

推荐答案

我将用逗号分割字符串,删除元素,然后再次加入字符串.希望这一切都可以在.NET 2.0中使用:

I would split the string on a comma, remove the element and then join the string again. Hopefully this all works in .NET 2.0:

string s = "76,60,12";
List<string> numbers = new List<string>(s.Split(','));
numbers.Remove("60");
s = string.Join(",", numbers.ToArray());

这篇关于从字符串数组中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆