3초기억력

Java Script - 문자열 자르기 본문

플밍_기타

Java Script - 문자열 자르기

잠수콩 2008. 11. 17. 15:38
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


어디서 퍼온거였는데, 기억안남.
한글, 영문 둘다 가능하다고는 하나, 잘안될때가 많음(특히 space 같은거)

'//문자열자르기 시작
function isstrlen(Str,CutLen)
    temp=0
    for CheckPoint=1 to len(Str)
        strTOasc=asc(mid(Str,CheckPoint,1))
        if strTOasc>0 and strTOasc<127 then
            temp=temp+1
        else
            temp=temp+2
        end if
        if temp<=CutLen then CutPoint=CheckPoint
    next
    if CutLen=0 then isstrlen=temp else isstrlen=CutPoint
end function

' Byte단위로 원하는 길이만큼 잘라서 AddStr값 뒤에 붙여주기
function cutstr(Str,MaxLen,AddStr)
    strlen=isstrlen(Str,0)
    if strlen>MaxLen then
        cutstr=left(Str,isstrlen(Str,MaxLen-len(AddStr))) & AddStr
    else
        cutstr=Str
    end if
end function
'//문자열자르기 끝

Comments