字符串去掉符号的问题

totsheng 2009-03-06 03:54:02
没有规律的字符串,想要把所有符号都去掉,只留字母、数字或者汉字?
请问该字符串怎么处理?
...全文
311 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
totsheng 2009-03-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 pztx1992 的回复:]
没看到汉字....


C# code

string s = "sdf$%^$%546";
string sNew = Regex.Replace(s,"\\W","");
[/Quote]
谢谢
pztx1992 2009-03-06
  • 打赏
  • 举报
回复
能帮我找找不加ref也能引用传递的例子吗
fancystyle 2009-03-06
  • 打赏
  • 举报
回复
用正则.如果是C#的话

Regex.Replace(subjectString, @"[^\w]", "", RegexOptions.IgnoreCase);
pztx1992 2009-03-06
  • 打赏
  • 举报
回复
没看到汉字....



string s = "sdf$%^$%546";
string sNew = Regex.Replace(s,"\\W","");
pztx1992 2009-03-06
  • 打赏
  • 举报
回复
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;

namespace CSDN
{
class Application
{
static void Main(string[] args)
{
string s = "sdf$%^$%546";
string sNew = Regex.Replace(s,"[^a-zA-Z0-9]","");
}
}
}
zhaozhijun0207 2009-03-06
  • 打赏
  • 举报
回复
那不是跟屏蔽sql注入一个原理

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧