---
title: "JAVA去空格"
author: "小色帝"
date: "2012-12-20T16:53:23Z"
tags: []
categories: ["Web前端"]
slug: "java"
draft: false
lastmod: "2012-12-20T16:53:23Z"
id: 1751180
url: "https://wangdingxin.iteye.com/blog/1751180"
---

String ccc=” he l l o , w o r l d “;
System.err.println(“去左边空格：”+ccc.replaceAll(“^\\s*”, “”)+”————”);
System.err.println(“去右边空格：”+ccc.replaceAll(“\\s*$”, “”)+”————”);
System.err.println(“去所有空格：”+ccc.replaceAll(“\\s”, “”)+”————”);
System.err.println(“去两端空格：”+ccc.replaceAll(“^\\s*(.*?)\\s*$”,”$1″)+”————”);