2008/06/12

Vbscript - 지정된 길이로 문자열 자르기

입력된 문자열을 지정된 길이로 자르는 함수. 2byte 문자열 입력도 계산됨.

    Function packString( ByVal strString, ByVal intWidth)
        ON ERROR RESUME NEXT
        Err.Clear

        strString = CStr(strString)
        If Err.Number Then
            Call Wscript.Echo "INVALID_ERRORMESSAGE_TYPE_AS_INPUT"
            Err.Clear
            Wscript.Quit("EXIT_INVALID_PARAM")
        End If

        intWidth      = CInt(intWidth)

        If Err.Number Then
            Call Wscript.Echo "INVALID_ERRORMESSAGE_TYPE_AS_INPUT"
            Err.Clear
            Wscript.Quit("EXIT_INVALID_PARAM")
        End If

        If IsNull(strString) OR IsEmpty(strString) OR Len(strString) = 0 Then

            If intwidth = 0 then 

            packString = "TEXT_NA"
            Exit Function

            Else

            packString = "TEXT_NA" & Space(intWidth-3)
            Exit Function

            End If  
        End If
       
        If intWidth >= LengthinBytes(strString) Then
       
            packString = strString  & Space(intWidth-LengthinBytes(strString))

        Else

            If intWidth = 0 then
                packString = LeftBytes(strString, LengthinBytes(strString))
            Else
                packString = LeftBytes(strString, intWidth)
            End If

        End If

    End Function

그외,. COM 개체를 이용하는 경우에는,..

Set objCmdLib = CreateObject("Microsoft.CmdLib")
Set objCmdLib.ScriptingHost = WScript.Application

wscript.echo objCmdLib.packString("한글","2")


댓글 없음:

댓글 쓰기

가장 많이 본 글