在.NET中用*替换*

时间:2015-03-27 09:32:56

标签: asp.net vb.net

我想从.net

中的字符串替换“*”

我的字符串是

  

四星药房有限责任公司***未通过W / S审核***

预期结果

  

四星药房有限责任公司未通过W / S审核

我尝试了这种模式但没有工作

  

[; /'*:?“”<> |]

请帮帮我

4 个答案:

答案 0 :(得分:1)

如果要删除它,则无需使用正则表达式:

Dim res = input.Replace("*", " ")

答案 1 :(得分:1)

您可以使用正则表达式:

myString = Regex.Replace(myString, @"\*+", " ");

或没有正则表达式:

string r = "Four Star Pharmacy LLC***failed W/S Audit***";
r = r.Replace("*", String.Empty);

之后你可以手动添加空格。

对于.Net 1.0 String.Empty不会占用堆上的额外空间,但“”需要堆上的存储及其在堆栈上的地址,从而产生更多的汇编代码。因此String.Empty比“”快。

String.Empty也表示没有拼写错误。

答案 2 :(得分:1)

试试这个:

if (this.value.match(/[^*]/g)) {
    this.value = this.value.replace(/[^*]/g, ' ');
}

答案 3 :(得分:1)

使用下一个模式:

new Regex(@"\*+").Replace("Four Star Pharmacy LLC***failed W/S Audit***", " ")