Avatar billede hektor Nybegynder
17. marts 2000 - 14:37 Der er 1 løsning

Forbedring ønskes

Følgende script skal lige forbedres en smule.
<%
Function FixTag(strTag, lngMaxLength)
    'Make sure all <BR> are written in capital letters
    Replace strTag, "<br>", "<BR>"
    strArr = Split(strTag, "<BR>")
   
    For lngCount = LBound(strArr) To UBound(strArr)
        If Len(strArr(lngCount)) > lngMaxLength Then 'We got a row that is bigger than allowed
          strArr(lngCount) = FixRow(strArr(lngCount), lngMaxLength)
        End If
    Next
   
   
    'Patch the tag together again, remove the trailing <BR>
    For lngCount = LBound(strArr) To UBound(strArr)
        strOut = strOut & strArr(lngCount) & ""
    Next
    FixTag = Left(strOut, Len(strOut))
End Function


Function FixRow(strText, lngMaxLength)   
    If Len(strText) > (2 * lngMaxLength) Then 'If the string is more than twice the length of maxlength, then we have to call the function again.
        strRest = FixTag(Mid(strText, lngMaxLength), lngMaxLength)
        strText = Left(strText, lngMaxLength - 1)
    End If

    For lngCount = (lngMaxLength) To 1 Step -1
        If Mid(strText, lngCount, 1) = " " OR Mid(strText, lngCount, 1) = "-" Then
            FixRow = Left(strText, lngCount) & "<BR>" & Mid(strText, lngCount + 1) & strRest
            Exit Function
        End If
    Next
    FixRow = Left(strText, lngMaxLength-1) & "<BR>" & Mid(strText, lngMaxLength) & strRest
End Function
%>

Problemet ligger i, at hvis man fx kalder den med en 50 tegns streng, og sætter 20 som max-længde, så sætter den kun eet <br> tag ind, og ikke 2 som er meningen.

Nogen som kan få den til at gøre det?
Avatar billede hektor Nybegynder
28. marts 2000 - 20:28 #1
åbenbart ikke
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester



IT-JOB

Udviklings- og Forenklingsstyrelsen

Generalister til PMO og strategiimplementering

Cognizant Technology Solutions Denmark ApS

Test Architect - Projects