728x90
public class testPjt {
public static void main(String[] args) {
String str = "가나다라마바사아자차 1111";
int cutBytes = 30;
String result = new String(str.getBytes(), 0, cutBytes);
System.out.println(result);
}
}
문자열 길이를 byte 단위로 가져오는 코드.
UTF-8 기준 한글 3Byte, 알파벳, 숫자, 띄어쓰기 1Byte
public class testPjt {
public static void main(String[] args) {
String errorMsg = "가나다라마바사아자차";
int byteLen = errorMsg.getBytes().length;
System.out.println(byteLen);
}
}
Byte 로 문자열을 자르는 방법
728x90
'개발관련 > JAVA' 카테고리의 다른 글
[JAVA] html에서 img 태그 src 이미지 URL 추출(Pattern 정규식 사용) (0) | 2025.03.26 |
---|---|
[Spring Error] cvc-complex-type.2.3: Element 'beans' cannot have character [children] (0) | 2023.04.21 |