使用 C# 从文本中删除数字 [英] Removing numbers from text using C#

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

问题描述

我有一个用于处理的文本文件,其中包含一些数字.我只想在其中输入文字,别无其他.我设法删除了标点符号,但是如何删除数字?我想要这个使用 C# 代码.

I have a text file for processing, which has some numbers. I want JUST text in it, and nothing else. I managed to remove the punctuation marks, but how do I remove the numbers? I want this using C# code.

另外,我想删除长度大于 10 的单词.如何使用 Reg 表达式来做到这一点?

Also, I want to remove words with length greater than 10. How do I do that using Reg Expressions?

推荐答案

您可以使用正则表达式:

You can do this with a regex:

string withNumbers = // string with numbers
string withoutNumbers = Regex.Replace(withNumbers, "[0-9]", "");

使用此正则表达式删除超过 10 个字符的单词:

Use this regex to remove words with more than 10 characters:

[\w]{10, 100}

100 定义要匹配的最大长度.不知道有没有最小长度的量词...

100 defines the max length to match. I don't know if there is a quantifier for min length...

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

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