从 VB.net 中的字符串中去除所有标点符号 [英] Strip all punctuation from a string in VB.net

查看:66
本文介绍了从 VB.net 中的字符串中去除所有标点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 vb.net 中的字符串中删除所有标点符号?我真的不想为每一个标点符号做 stringname.Replace("$", "") ,尽管它可以工作.

How do I strip all punctuation from a string in vb.net? I really do not want to do stringname.Replace("$", "") for every single bit of punctuation, though it would work.

我如何快速有效地做到这一点?

How do i do this quickly and efficiently?

除了为我编码一些东西之外......

Other than coding something that codes this for me....

推荐答案

您可以使用正则表达式来匹配要删除的任何内容:

You can use a regular expression to match anything that you want to remove:

str = Regex.Replace(str, "[^A-Za-z]+", String.Empty);

[^...] 是一个否定集合,它匹配不在集合中的任何字符.你可以把任何你想保留的字符放在那里.

[^...] is a negative set that matches any character that is not in the set. You can just put any character there that you want to keep.

这篇关于从 VB.net 中的字符串中去除所有标点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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