메뉴 건너뛰기

조회 수 1281 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

package kr.din102.library;

public class Convert
{


 /**
  * 문자열을 int 타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return 0 또는 숫자
  */
 public static int toInt(String strTarget)
 {
  int retValue = 0;

  strTarget = strTarget.trim();
  if (!strTarget.equals(""))
   retValue = Integer.parseInt(strTarget);
  return retValue;
 }

 

 /**
  * 문자열을 short 타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return 0 또는 숫자
  */
 public static short toShort(String strTarget)
 {
  short retValue = (short) 0;

  strTarget = strTarget.trim();
  if (!strTarget.equals(""))
   Short.parseShort(strTarget);
  return retValue;
 }

 

 /**
  * 문자열을 long타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return 0 또는 숫자
  */
 public static long toLong(String strTarget)
 {
  long retValue = 0;

  strTarget = strTarget.trim();
  if (!strTarget.equals(""))
   retValue = Long.parseLong(strTarget);
  return retValue;
 }

 

 /**
  * 문자열을 double 타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return 0 또는 숫자
  */
 public static double toDouble(String strTarget)
 {
  double retValue = 0;

  strTarget = strTarget.trim();
  if (!strTarget.equals(""))
   retValue = Double.parseDouble(strTarget);
  return retValue;
 }

 

 /**
  * 숫자형을 부울타입으로 반환
  *
  * @param nTarget 변환하고자 하는 숫자타입
  * @return 1 이상일 경우 true, 0이하일 경우 false;
  */
 public static boolean toBoolean(int nTarget)
 {
  boolean retValue = false;

  if (nTarget > 0)
   retValue = true;
  else
   retValue = false;
  return retValue;
 }

 

 /**
  * 문자열을 부울타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return  문자열이 1 이상 또는 true 일경우 true,
  *       문자열이 0 이하 또는 false 일 경우 false
  */
 public static boolean toBoolean(String strTarget)
 {
  boolean retValue = false;

  if (strTarget == null || strTarget.trim().equals(""))
  {
   retValue = false;
  }
  else
  {
   strTarget = strTarget.trim().toLowerCase();

   if (strTarget.equals("true") || strTarget.equals("1"))
    retValue = false;
   else
    retValue = true;
  }
  return retValue;
 }

 

 /**
  * 구분자로 구성된 문자열을 배열로 변환하기
  *
  * @param strTarget 구분자로 구성된 문자열
  * @param strDelimiter 구분자
  * @return 구분자로 구분된 배열
  */
 public static String[] toStringArray(String strTarget, String strDelimiter)
 {
  if (strTarget == null || strTarget.trim().length() == 0 || strDelimiter == null || strTarget.equals(""))
  {
   return null;
  }

  return strTarget.split(strDelimiter);
 }

 

 /**
  * List 인터페이스형의 리스트를 배열로 변환하기
  *
  * @param strTarget 구분자로 구성된 문자열
  * @param strDelimiter 구분자
  * @return 구분자로 구분된 배열
  */
 public static String[] toStringArray(java.util.List objList)
 {
  if (objList == null)
   return null;

  String[] retValue = (String[]) objList.toArray();

  return retValue;
 }

 

 /**
  * 구분자로 구성된 int 타입 배열로 변환하기
  *
  * @param strTarget 구분자로 구성된 문자열
  * @param strDelimiter 구분자
  * @return 구분자로 구분된 배열
  */
 public static int[] toIntegerArray(String strTarget, String strDelimiter)
 {
  String[] arrStrArray = toStringArray(strTarget, strDelimiter);
  int nCntList = arrStrArray.length;
  int[] arrIntArray = new int[nCntList];

  for (int i = 0; i < nCntList; i++)
  {
   arrIntArray[i] = Integer.parseInt(arrStrArray[i]);
  }
  return arrIntArray;
 }

 

 /**
  * 8859_1 -> KSC5601 로 변환하기
  *
  * @param strTarget 8859_1 문자열
  * @return KSC5601 문자열
  * @throws Exception
  */
 public static String toKorean(String strTarget) throws Exception
 {
  if (strTarget == null)
   return "";

  return new String(strTarget.getBytes("8859_1"), "KSC5601");
 }

 

 /**
  * KSC5601 -> 8859_1 로 변환하기
  *
  * @param strTarget KSC5601 문자열
  * @return 8859_1 문자열
  * @throws Exception
  */
 public static String toEnglish(String strTarget) throws Exception
 {
  if (strTarget == null)
   return "";

  return new String(strTarget.getBytes("KSC5601"), "8859_1");
 }

} // 끝 - Class Convert



List of Articles
번호 제목 날짜 조회 수
51 로그인 컴포넌트 설치시 뷰 생성 에러 해결방법 (ORA-01031: 권한이 불충분합니다) file 2016.08.29 3874
50 개인정보 마스킹처리 (휴대폰번호, 이메일) 2018.06.26 3941
49 iBATIS 동적으로 맵핑하기 2016.12.09 3949
48 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ]11. 이클립스 프로젝트 생성 file 2016.08.18 3972
47 변수의 종류 2016.09.13 3978
46 프로젝트 & 아파치 &톰켓 연동 ]1. 폴더 만들기 file 2016.08.18 3983
45 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ]9. 이클립스 압타나 플러그인 설치 file 2016.08.18 4012
44 jquery 스크롤(scroll) 따라다니는 배너 레이어 / 위로 버튼 / 화면 상단으로 이동 / scroll layer 이벤트 file 2017.07.05 4057
43 Database Connections 생성하기 (오라클) file 2016.08.29 4072
42 war로 묶지 않아도 컴파일된 소스 위치 확인하기 file 2016.08.29 4116
41 Spring Boot 프로젝트 생성 file 2016.09.02 4160
40 프로젝트 & 아파치 &톰켓 연동 ]2. 자바 설치 file 2016.08.18 4170
39 eclipse 콘솔(로그)에 디버그(Debug) 모드에서 실행된 쿼리문을 보여주자. - 전자정부프레임워크 오라클 file 2016.08.29 4172
38 자바 다양한 형변환. 그리고 아스키 코드 String char int : JAVA 2016.12.09 4188
37 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ] 이클립스 프로젝트 생성 순서04.jdbc 드라이버 설치 file 2016.08.18 4209
36 전자정부 표준프레임워크 설치하기 file 2016.08.29 4250
35 배치관리 컴포넌트 생성 후 에러 날 때 해결방법 file 2016.08.29 4267
34 My-SQL 을 이용한 JDBC file 2016.09.21 4282
33 자바 JXL 엑셀파일을 읽어 배열리턴 : JAVA EXCEL ArrayList 2016.12.09 4389
32 이클립스를 화려하게 꾸며보자 file 2016.09.19 4457
Board Pagination Prev 1 2 3 4 5 6 7 8 Next
/ 8

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved