랭귀지/ASP
[ASP]문자관련함수
유키공
2017. 12. 22. 15:30
- 문자열 바이트길이 가져오기
예)str=CutString(str,15)
'--------------------------------------------------------
' Function Name : GetLength
' Description : 문자열 바이트길이 가져오기
' Example : GetLength("문자열")
' output : 6
' --------------------------------------------------------
Function GetLength(strText)
Dim nByteLen, nIdx, nLenIdx, nTextLenth
If IsNull(strText) Then
GetLength = 0
Exit Function
End If
nByteLen = 0
nTextLenth = Len(strText)
nIdx = 1
For nLenIdx = 1 To nTextLenth
If Asc(Mid(strText, nIdx, 1)) < 0 Then
nByteLen = nByteLen + 2
Else
nByteLen = nByteLen + 1
End If
nIdx = nIdx + 1
Next
GetLength = nByteLen
End function
-문자열 바이트 단위로 자르기
' --------------------------------------------------------
' Function Name : SetLengthNew
' Description : 문자열 바이트 단위로 자르기
' Example : SetLengthNew("문자열 테스트", 10, "|")
' output : 문자열 테|
' --------------------------------------------------------
Function SetLengthNew(strText, cutCount, replaceStr)
Dim nIdx, nLenIdx, strResult
nIdx = 1
If GetLength(strText) > cutCount Then
For nLenIdx = 0 To cutCount
If Asc(Mid(strText, nIdx, 1)) <= 0 Then
If nLenIdx = cutCount - 1 Then
Exit For
End If
nLenIdx = nLenIdx + 1
End If
strResult = strResult & Mid(strText, nIdx, 1)
nIdx = nIdx + 1
Next
strResult = strResult & replaceStr
Else
strResult = strText
End If
SetLengthNew = strResult
End Function
- 문자길이 제한예)str=CutString(str,15)
Public Function CutString(str, strlen) Dim rValue Dim nLength Dim f Dim tmpStr Dim tmpLen nLength = 0.00 rValue = "" for f = 1 to Len(str) tmpStr = MID(str,f,1) tmpLen = ASC(tmpStr) if(nLength >= strlen-1) then rValue = rValue & "..." exit for end if if(tmpLen < 0) then '//한글 nLength = nLength + 2 '//한글일때 길이값 설정 rValue = rValue & tmpStr elseif(tmpLen >= 97 and tmpLen <= 122) then '//영문 소문자 nLength = nLength + 1 '//영문소문자 길이값 설정 rValue = rValue & tmpStr elseif(tmpLen >= 65 and tmpLen <= 90) then '//영문 대문자 nLength = nLength + 1 '//영문대문자 길이값 설정 rValue = rValue & tmpStr else '//그외 키값 nLength = nLength + 1 '//특수문자 기호값... rValue = rValue & tmpStr end if next cutString = rValue End Function- 글자수 제한
Function TextCut(CheckValue,LenNum) If len(CheckValue) > LenNum then TextCut = mid(CheckValue,1,LenNum)&".." Else TextCut = CheckValue End If End Function- 저장시 특수 문자 변경
Function SaveCheckWord(CheckValue) If Len(CheckValue) > 0 Then CheckValue=replace(CheckValue, "&" ,"&") CheckValue=replace(CheckValue, "<" ,"<") CheckValue=replace(CheckValue, ">" ,">") CheckValue=replace(CheckValue, "'" ,"&qout;") SaveCheckWord = CheckValue Else SaveCheckWord = "" End If End Function- 출력시 TextBox에 태그포함가능하게
Function ReplaceCheckWord(CheckValue) Dim lt_Length,gt_Length,mid_Length,TempCheckValue1,TempCheckValue2 If Len(CheckValue) > 0 Then lt_Length = instr(CheckValue,"<") gt_Length = instr(CheckValue,">") If lt_Length > 0 AND gt_Length > 0 Then If lt_Length > gt_Length Then ReplaceCheckWord = CheckValue Else mid_Length = ( gt_Length - lt_Length ) + 1 TempCheckValue1 = Mid(CheckValue,lt_Length,mid_Length) TempCheckValue2 = Replace(TempCheckValue1,""","'") CheckValue = Replace(CheckValue,TempCheckValue1,TempCheckValue2) ReplaceCheckWord = CheckValue End If Else ReplaceCheckWord = CheckValue End If Else ReplaceCheckWord = "" End If End Function-Isnull = ""
Function IsNullIsSpace(CheckValue) If Len(CheckValue) > 0 Then IsNullIsSpace = CheckValue Else IsNullIsSpace = "" End If End Function- 아큐먼트에 길의 빈값만큼 0으로 체운다.
Function null_PadingZero(arg_len ,arg) dim a For a=1 To arg_len If Len(arg)=arg_len Then null_PadingZero =arg Else arg="0"&arg End if Next End Function