[Classic ASP] 문자 채우기, 자르기(한글) 함수
Wdev
2014-04-30

문자 채우기


문자(숫자)를 출력하면서 특정문자를 결합하는 경우에 사용한다
 - 숫자 "1"을 네자리의 Numneric(빈자리가 "0"로 채워진) 4자리로 변환 하는 경우
   1 => "0001"
 - 좌우측으로 여백문자처리의 경우

 • FillString() : 특정문자 채우기
 • FillZero() : "0" 문자 채우기
 • FillSpace() : 스페이스 채우기

문자 자르기

mid() 함수를 이용하여 문자를 자르는 경우 2byte 문자도 자릿수에 상관 없이 1문자로 처리되기 떄문에 의도한 것보다 길게 나오는 경우가 많은데 2byte 문자를 감안하여 해당 자릿수에서 문자를 잘라 반환 한다
 - 게시판의 제목 등 길어질 수 있는 내용을 좁은 구역에 출력시 유효
 - 지정길이보다 긴 경우 +More 사용

 • HLeftB() : 2byte 문자 자르기
 • HLeftBMore() : 2byte 문자 자른 후 길이가 넘는 경우 "…" 문자 추가

<%
'===============================================
' >> Fill Stuff functions
'
' FillZero( cString, iLength )
' FillSpace( cString, iLength )
' FillString( cString, iLength, cFillString )
'
'===============================================

function FillZero( cString, iLength )
	FillZero = FillString( cString, iLength, "0" )
end function

function FillSpace( cString, iLength )
	FillSpace = FillString( cString, iLength, " " )
end function

function FillSpaceRight( cString, iLength )
	FillSpaceRight = FillStringRight( cString, iLength, " " )
end function

function FillString( cString, iLength, cFillString )
	if( iLength >Len(cString) ) then
		FillString = ( String( iLength -Len( cString ), cFillString ) & cString )
	else
		FillString = cString
	end if
end function

function FillStringRight( cString, iLength, cFillString )
	if( iLength >Len(cString) ) then
		FillStringRight = ( cString & String( iLength -Len( cString ), cFillString ) )
	else
		FillStringRight = cString
	end if
end function

function HLeftB( cString, iLen ) 
	dim i, c, a, b
	dim cReturn
	
	b = 0
	cReturn = ""
	
	if not IsNull(cString) then
		for i = 1 to Len(cString)
			c = mid(cString,i,1)
			a = asc(c)
			cReturn = cReturn&c
			
			if (a>255 or a<0) then
				b = b+2
			else
				b = b+1
			end if
			
			if (iLen=<b) then
				exit for
			end if
		next
	end if
		
	HLeftB = cReturn
end function

function HLeftBMore( cString, iLen ) 
	dim c
	
	c = HLeftB( cString, iLen ) 
	if (cString>c) then
		c = c &"…"
	end if
	
	HLeftBMore = c
end function
%>
저작권자 © WDEV, 무단전재 및 재배포 금지
ASP/PHP 분류 내의 이전기사