您的位置: 首页 > IT文章 > string去空格 string去空格 分类: IT文章 • 2022-07-23 21:31:08 众所周知,string字符串去除空格的方法有trim()和replace(),区别在于trim()去首尾的空格,但是不能去中间的,而replace可以去除所有的空格。 string data1=" a b c "; data1=data1.trim(); 结果为"a b c"。 string data1="a b c "; data1=data1.Replace(" ", "") 结果为“abc”。