import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;
/**
* 类: <code> FullCharConverter </code>
* 功能描述: 文章的全角和半角转换
* 创建人:
* 创建日期: 2013-8-30 上午10:22:28
* 开发环境: JDK6.0
*/
public class FullCharConverter {
public static void main(String[] args) throws UnsupportedEncodingException {
String pageSplit9 = "<div style=\"page-break-after: always;\">\r\n\t<span style=\"display: none;\"> </span></div>";
String pageSplit = "<div style=\"page-break-after: always\">\r\n\t<span style=\"display: none;\"> </span></div>";
String str="xiaoqiang"+pageSplit+pageSplit9+"。" ;
String strPage=pageSplit+pageSplit9+"。";
System.out.println((pageSplit+pageSplit9).length());
String sss="";
if(str.indexOf(strPage)!=-1)
{
sss+=str.subSequence(0, str.indexOf(strPage)-1)+pageSplit+pageSplit9+str.charAt(str.indexOf(strPage)-1)+str.substring(179+str.indexOf(strPage),str.length())+"。";
}
System.out.println(str);
System.out.println("<<<<<<<<>>>>>>>>>>");
System.out.println(sss);
/* // 全角转半角
String QJstr = "hello!! 全角转换,DAO 53232abcdefghijklmnopqrsduvwyz ";
String result = full2HalfChange(QJstr);
System.out.println(QJstr);
System.out.println(result);
System.out.println("------------------------------------");
// 半角转全角
String str = "java 汽车 召回 1234567890abcdefghijklmnopqrstuvwxyz,./;'<>{}";
System.out.println(str);
System.out.println(str.length());
System.out.println(half2Fullchange(str));
System.out.println(half2Fullchange(str).length());*/
}
/**
* 功能描述:全角转半角的 转换函数
* @param QJstr 需要转换的字符
* @return 返回转换后的半角字符
* @throws UnsupportedEncodingException
*/
public static final String full2HalfChange(String QJstr)
throws UnsupportedEncodingException {
StringBuffer outStrBuf = new StringBuffer("");
String Tstr = "";
byte[] b = null;
for (int i = 0; i < QJstr.length(); i++) {
Tstr = QJstr.substring(i, i + 1);
// 全角空格转换成半角空格
if (Tstr.equals(" ")) {
outStrBuf.append(" ");
continue;
}
b = Tstr.getBytes("unicode");
// 得到 unicode 字节数据
if (b[2] == -1) {
// 表示全角?
b[3] = (byte) (b[3] + 32);
b[2] = 0;
outStrBuf.append(new String(b, "unicode"));
} else {
outStrBuf.append(Tstr);
}
} // end for.
return outStrBuf.toString();
}
/**
* 功能描述:半角转全角
* @param QJstr 需要转换的字符
* @return 返回转换后的全角字符
* @throws UnsupportedEncodingException
*/
public static final String half2Fullchange(String QJstr)
throws UnsupportedEncodingException {
StringBuffer outStrBuf = new StringBuffer("");
String Tstr = "";
byte[] b = null;
for (int i = 0; i < QJstr.length(); i++) {
Tstr = QJstr.substring(i, i + 1);
if (Tstr.equals(" ")) {
// 半角空格
outStrBuf.append(Tstr);
continue;
}
b = Tstr.getBytes("unicode");
if (b[2] == 0) {
// 半角?
b[3] = (byte) (b[3] - 32);
b[2] = -1;
outStrBuf.append(new String(b, "unicode"));
} else {
outStrBuf.append(Tstr);
}
}
return outStrBuf.toString();
}
public static final String checkSign(String QJstr)
throws UnsupportedEncodingException {
Pattern patPunc = Pattern.compile("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]");
return "";
}
}