string去空格

众所周知,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”。

原文地址:https://www.cnblogs.com/douglas0126x/p/4957451.html