如何从List< string>中的字符串中删除数字/数字? [英] How can I remove numbers/digits from strings in a List<string>?

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

问题描述

我有一个字符串列表:

List<string> _words = ExtractWords(strippedHtml);

_words 包含1799个索引;每个索引中都有一个字符串.

_words contains 1799 indexes; in each index there is a string.

某些字符串仅包含数字,例如:

Some of the strings contain only numbers, for example:

"2" "2013"​​

我想删除这些字符串,所以最后,列表将仅包含带字母的字符串,而不包含数字.

I want to remove these strings and so in the end the List will contain only strings with letters and not digits.

"001hello" 这样的字符串是可以的,但是"001" 则不是,应该将其删除.

A string like "001hello" is OK but "001" is not OK and should be removed.

推荐答案

您可以为此使用LINQ:

You can use LINQ for that:

_words = _words.Where(w => w.Any(c => !Char.IsDigit(c))).ToList();

这会过滤掉完全由数字组成的字符串以及空字符串.

This would filter out strings that consist entirely of digits, along with empty strings.

这篇关于如何从List&lt; string&gt;中的字符串中删除数字/数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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