Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- WebView
- 인코딩
- 이클립스
- jsp
- C#
- java
- XML
- permgen space
- udp
- Eclipse
- 메모리
- encoding
- Memory
- ios
- 톰켓
- 티스토리 초대
- jQuery
- MySQL
- 티스토리 초대장
- HTML
- JavaScript
- ipad
- Android
- Tomcat
- spring
- Objective C
- 한글
- Database
- UIWebView
- iphone
Archives
- Today
- Total
suroMind
[JAVA]java 한글 자르기 본문
출처 : http://pmguda.com/579
여러 메소드를 사용해 봤지만 아래 메소드는 잘되네요.
단 UTF-8환경에서만 테스트 해봤습니다.
인코딩 환경에 따라 다르다고 하는데 일단 되니깐 패스..
public String subStringBytes(String str, int byteLength) {
// String 을 byte 길이 만큼 자르기.
int retLength = 0;
int tempSize = 0;
int asc;
if(str == null || "".equals(str) || "null".equals(str)){
str = "";
}
int length = str.length();
for (int i = 1; i <= length; i++) {
asc = (int) str.charAt(i - 1);
if (asc > 127) {
if (byteLength >= tempSize + 2) {
tempSize += 2;
retLength++;
} else {
return str.substring(0, retLength) + "...";
}
} else {
if (byteLength > tempSize) {
tempSize++;
retLength++;
}
}
}
return str.substring(0, retLength);
}
'IT분야 > Java' 카테고리의 다른 글
| [전자정부프레임워크]기본 환경설정 (2) | 2013.03.07 |
|---|---|
| [Spring]controller에서 cookie 만들기 (0) | 2013.02.26 |
| OEPE eclipse 버전별 링크 (0) | 2013.02.26 |
| [Eclipse]이클립스 톰켓 경로 변경시 추가 안될때 (0) | 2012.11.04 |
| [Java]Tomcat PermGen space (0) | 2012.04.08 |
Comments