A cópia do código é a seguinte:
/*
* Copyright 2012-2013 The Haohui Network Corporation
*/
pacote com.haohui.common.utils;
/**
* <pre>
* String Helper
* </pre>
*
* @Project Baidamei
* @author cevencheng <[email protected]>
* @create 2012-11-30 14:42:56
*/
classe pública StringTool {
/**
*<b> Interceptar uma sequência de comprimento de byte especificado não pode retornar metade de um caractere chinês </b>
*Por exemplo:
*Se a página da web puder exibir até 17 caracteres chineses, o comprimento será 34
* Stringtool.getSubstring (str, 34);
*
* @param str
* @param Comprimento
* @retornar
*/
public static string getsubstring (string str, int length) {
int conting = 0;
int offset = 0;
char [] c = str.toCharArray ();
for (int i = 0; i <c.Length; i ++) {
if (c [i]> 256) {
deslocamento = 2;
contagem += 2;
} outro {
deslocamento = 1;
contagem ++;
}
if (count == comprimento) {
return str.substring (0, i + 1);
}
if ((count == comprimento + 1 && offset == 2)) {
retornar str.substring (0, i);
}
}
retornar "";
}
}