Java tutorial
//package com.java2s; /* * @(#)ModelStringUtil.java * * Copyright (C) 2006-2011 www.interpss.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE * as published by the Free Software Foundation; either version 2.1 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * @Author Mike Zhou * @Version 1.0 * @Date 02/15/2008 * * Revision History * ================ * */ public class Main { /** * a Chinese character takes up two-char-space but only counts one char, this method * replace the Chinese Character with "aa"(just arbitrary chosen here),with dealing with * operations like String.subString(int beginIdx,int endIdx); * @param s * @return a String with all the Chinese Character in it replaced by "aa" */ public static String replaceChineseChar(String s) { String regEx = "[\u4e00-\u9fa5]"; String tem = s.replaceAll(regEx, "aa"); return tem; } }