2009/12/19 21:51 CodeIN/Java
크리에이티브 커먼즈 라이선스
Creative Commons License

으.. 역시나 한글은 문제를 일으키는구나... ㅎ


전문 통신할 때는 약속된 길이 만큼 정확하게 보내줘야 합니다. 그렇지 않으면... 항상 문제를 일으키고는 하죠..  뭐 한글이 문제는 아니지만요 ㅎ

보통 format을 맞추는 가장 쉬운 방법은 다음아래와 같습니다.

String.format("%-200s", communication);
communication의 원래 값 포함해서 Length가 200인 String을 return한다.

물론 String.format이 이런 식으로 원하는 Length만큼 format을 만들어 주기는 하지만 원래 목적은 이런게 아닌듯 싶다. 하지만 전문 통신할 때 이렇게 사용하면 굉장히 편리하다.

아래는 전문 통신하기 위해서 String length 100을 만들어 주는 소스이다.
sendMessage =
   String.format("%-12s", a) +
   String.format("%-6s", b)+
   String.format("%-22s", c) +
   String.format("%-60s", d);

이렇게 하면은 정확히 String length 100으로 보내게 된다.



하지만 어제 문제가 일어 났던 이유는 한글 사용 때문이며, 서버측이 c언어라서 문제가 발생했다.

String a = "김태정";
System.out.println(a.length);                          <- String length 3
System.out.println(a.getBytes().length);        <-  byte length 6
 
실행결과
3
6

문제가 일어난 원인은 위 소스와 같다.
한글은 2bytes 이므로 String length를 체크하게 되면은 "김태정"의 length는 3이 되지만, c언어에는 String이 없으므로 6이 된다.




'CodeIN > Java' 카테고리의 다른 글

[java] Excel 파일 읽기 xls, xlsx  (9) 2010/02/01
[log4j] package 별로 로그 남기기  (1) 2009/12/19
[java] String format 그리고 한글  (0) 2009/12/19
[log4j] Log4j HTML TABLE  (0) 2009/12/13
[log4j] ConversionPattern  (0) 2009/12/12
[log4j] log4j.properties 설정  (0) 2009/12/11
posted by 조금까칠한남자
2009/10/28 20:19 CodeIN/Java
크리에이티브 커먼즈 라이선스
Creative Commons License

전문통신 할 때, 한글 때문에 문제가 많다 ㅠㅡ
String을 byte로 변환해서 원하는 길이만큼 가져와서 String으로 만드는 방법.

소스.
String temp = "PC8000오늘두우리는달린다.           ";
byte[] t = temp.getBytes();
String a = new String(t, 0, 1);
String b = new String(t, 1, 1);
String c = new String(t, 2, 4);
String d = new String(t, 6, 30);
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);


String 생성자에 사용된 parameter 입니다.
String(byte[] bytes, int offset, int length, String charsetName)


결과값.
P
C
8000
오늘두우리는달린다.       

posted by 조금까칠한남자
2009/06/23 19:54 MiPlatform
크리에이티브 커먼즈 라이선스
Creative Commons License

일단 기본적인 sorting에 관해서는 아래 링크를 통해서 알아봤습니다.

http://www.voiceportal.co.kr/582

 

이번에는 sorting시에 문제가 발생했던 점에 대해서 알아보겠습니다.

오늘 이것 저것 테스트를 해보는데 sort시에 이런 문제가 발생되었습니다.

sort할 column의 data type이  숫자가 아니라 문자로 되어 있는 듯 합니다.

 

실제로 확인을 해보니,

위에서 사용한 Grid에 바인딩 되어 있는 Dataset의 설정 값들을 보니까, access_ranking으로 되어 있었습니다.

 

 

그래서 INT로 수정을 해보니 아래와 같이 제대로 sort가 됩니다.

 

 

 

마이플랫폼에서는 크게 data type이 중요하다고 생각되지 않아서  미쳐 신경을 쓰지 못했던 것 같습니다. 물론 data type은 항상 정확하게 설정을 해주어야지요 :D

 

 

 

허거거... 근데 data type이 String인데도 제대로 sorting이 되는것이 있다...

ㅡㅡ^

마이플랫폼을 하다보면은 가끔 기준이 없는 몇몇 것들이 있기는 한데....

아... ㅡ_-;;

 

 

 

 

 

 

 

 

posted by 조금까칠한남자
2009/02/20 14:14 CodeIN/Web
크리에이티브 커먼즈 라이선스
Creative Commons License
The JavaScript function for String Replace replaces the first occurrence in the string. The function is similar to the php function str_replace and takes two simple parameters. The first parameter is the pattern to find and the second parameter is the string to replace the pattern with when found. The javascript function does not Replace All...
str = str.replace(”find”,”replace”)

To ReplaceAll you have to do it a little differently. To replace all occurrences in the string, use the g modifier like this:
str = str.replace(/find/g,”replace”)

posted by 조금까칠한남자
2008/07/25 17:07 CodeIN/Java
크리에이티브 커먼즈 라이선스
Creative Commons License

문자열을 구분자로 자르고 싶을때



"1:2:3::::" 문자열을 ":" 기준으로 자른다.



1. limit 가 0인 경우

String abc = "1:2:3::::";

String regex = ":";

int limit = 0;

String[] results = abc.split(regex, limit);


결과 {"1", "2", "3"}

zero length string 은 무시된다.



2. limit 가 양수인 경우

String abc = "1:2:3::::";

String regex = ":";

int limit = 5;

String[] results = abc.split(regex, limit);


결과 {"1", "2", "3", "", "::"}

배열의 최대개수는 limit를 넘지 못한다.



3. limit 가 음수인 경우

String abc = "1:2:3::::";

String regex = ":";

int limit = -1;

String[] results = abc.split(regex, limit);


결과 {"1", "2", "3", "", "", "", ""}

zero length string 도 포함한다.


posted by 조금까칠한남자
TAG Java, split, string
2008/04/10 17:30 CodeIN/Java
크리에이티브 커먼즈 라이선스
Creative Commons License

사용법 예:
System.getProperty("java.runtime.name");

java.runtime.name ===> Java(TM) 2 Runtime Environment, Standard Edition
sun.boot.library.path ===> C:\j2sdk1.4.2_03\jre\bin
java.vm.version ===> 1.4.2_03-b02
java.vm.vendor ===> Sun Microsystems Inc.
java.vendor.url ===> http://java.sun.com/
path.separator ===> ;
java.vm.name ===> Java HotSpot(TM) Client VM
file.encoding.pkg ===> sun.io
user.country ===> KR
sun.os.patch.level ===> Service Pack 4
java.vm.specification.name ===> Java Virtual Machine Specification
user.dir ===> C:\Documents and Settings\Administrator\바탕 화면
java.runtime.version ===> 1.4.2_03-b02
java.awt.graphicsenv ===> sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs ===> C:\j2sdk1.4.2_03\jre\lib\endorsed
os.arch ===> x86
java.io.tmpdir ===> C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\
line.separator ===>
java.vm.specification.vendor ===> Sun Microsystems Inc.
user.variant ===>
os.name ===> Windows 2000
sun.java2d.fontpath ===>
java.library.path ===> C:\j2sdk1.4.2_03\bin;.;C:\WINNT\system32;C:\WINNT;.;C:\j2
sdk1.4.2_03\bin;C:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Pro
gram Files\Oracle\jre\1.1.8\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbe
m;F:\apache-ant-1.5.3-1\bin;C:\Program Files\SecureCRT\;C:\Program Files\SSH Com
munications Security\SSH Secure Shell
java.specification.name ===> Java Platform API Specification
java.class.version ===> 48.0
java.util.prefs.PreferencesFactory ===> java.util.prefs.WindowsPreferencesFactory
os.version ===> 5.0
user.home ===> C:\Documents and Settings\Administrator
user.timezone ===>
java.awt.printerjob ===> sun.awt.windows.WPrinterJob
file.encoding ===> MS949
java.specification.version ===> 1.4
user.name ===> Administrator
java.class.path ===> .;
java.vm.specification.version ===> 1.0
sun.arch.data.model ===> 32
java.home ===> C:\j2sdk1.4.2_03\jre
java.specification.vendor ===> Sun Microsystems Inc.
user.language ===> ko
awt.toolkit ===> sun.awt.windows.WToolkit
java.vm.info ===> mixed mode
java.version ===> 1.4.2_03
java.ext.dirs ===> C:\j2sdk1.4.2_03\jre\lib\ext
sun.boot.class.path ===> C:\j2sdk1.4.2_03\jre\lib\rt.jar;C:\j2sdk1.4.2_03\jre\li
b\i18n.jar;C:\j2sdk1.4.2_03\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2_03\jre\lib\jsse
.jar;C:\j2sdk1.4.2_03\jre\lib\jce.jar;C:\j2sdk1.4.2_03\jre\lib\charsets.jar;C:\j
2sdk1.4.2_03\jre\classes
java.vendor ===> Sun Microsystems Inc.
file.separator ===> \
java.vendor.url.bug ===> http://java.sun.com/cgi-bin/bugreport.cgi
sun.cpu.endian ===> little
sun.io.unicode.encoding ===> UnicodeLittle
sun.cpu.isalist ===> pentium i486 i386


posted by 조금까칠한남자
prev 1 next