바이트로 처리하면 구할 수 있습니다.


[ Follow Ups ] [ Post Followup ] [ 자바 묻고 답하기 ]

Posted by 윤경구 on September 04, 1997 at 21:43:36:

In Reply to: String에서 유니코드가 아닌 실제 문자 갯수 구하는 방법 posted by 최석주 on September 04, 1997 at 21:05:01:


class lengthtest {
static int getlength(String str) {
byte[] bytes=str.getBytes();
return bytes.length;
}


public static void main(String args[]) {
if (args.length<1) {
System.out.println("Usage: lengthtest string");
}
else {
System.out.println("Result="+getlength(args[0]));
}
}
}


> java lengthtest ABCD한글


결과로 8이 나옵니다.


Follow Ups:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ Follow Ups ] [ Post Followup ] [ 자바 묻고 답하기 ]