首页 > 技术文章 > string去空格

douglas0126x 2015-11-11 21:54 原文

众所周知,string字符串去除空格的方法有trim()和replace(),区别在于trim()去首尾的空格,但是不能去中间的,而replace可以去除所有的空格。

 


  1. string data1=" a b c ";  
  2. data1=data1.trim();  

结果为"a b c"。

 


  1. string data1="a b c ";  
  2. data1=data1.Replace(" ", "")  

结果为“abc”。

推荐阅读