用Trim()方法就可以了: String s = " 去掉空格 "; s = s.Trim(); 转载于:https://www.cnblogs.com/henw/archive/2011/05/13/2045566.html