有一个字符串“str=1 3 45. 7 8 9 0 5”,要去除其中所有的空格,使字符串变为“str=1345.78905”,这个方法应该怎样写,都有那些不同的方法???
解决方案 »
- FreeTextBox的上传图片问题,怎么上传本地图片??
- C#导出数据到EXCEL怎么判断单元格是否建立
- asp.net如何关闭网页?
- web类中引用webbrowser出错
- [馨郁星愿] sql 求和 ,有点复杂.慎入
- 求助 基于mapxtreme+asp.net 为什么无法获得图层?
- vs2005 ASP.NET c#没有了框架页 ,如何做象MSDN这样
- 谁能提供一个HTML组件(WebService.htc)的下载地址?
- 请问asp.net中还可以使用struct来定义结构以及使用类(class)吗?
- 请问,asp.net中 如何交互页面和类文件?
- 网站调用本机的批处理,没反应
- 【散分】不用正则,60行代码搞定高效Url重写,附示例代码下载
这个方法就可以解决
Regex.Replace(str,@"\s","")
string str = "1 3 45. 7 8 9 0 5";
Response.Write(str.Replace(" ",""));
http://www.cnblogs.com/kym/archive/2009/12/07/1618293.html
//最常用的就是这个了
str.Replace(" ", "")
{
if (!IsPostBack)
{
string s = "str=1 3 45. 7 8 9 0 5";
Response.Write(tripBlank(s));
}
} public string tripBlank(string s)
{
string newstr = string.Empty;
CharEnumerator ce = s.GetEnumerator();
while (ce.MoveNext())
{
byte[] array = new byte[1];
array = System.Text.Encoding.ASCII.GetBytes(ce.Current.ToString());
int asciicode = (short)(array[0]);
if (asciicode != 32)
{
newstr+= ce.Current.ToString();
}
}
return newstr;
}
超简单的说
如果要写入数据库,还可以用RARIM函数,
str.replace(/\s/gi,"")应该OK了
str.Replace(" ", "");
str=str.Replace(" ", "").Replace(" ", "")
string newStr = str.replace(" ", string.Empty);
快一些