31. december 2010 - 23:22Der er
5 kommentarer og 1 løsning
<br> efter 300 tegn
Hey.
Jeg leder efter noget der automatisk går ind i en besked og laver et break (<br>) efter 300 tegn, så den ikke bare fortsætter og smadrer min tabel. Jeg har ikke leget meget med denne funktion, men jeg tror det noget a la:
for i AntalTegn 300
if i > 300 then response.write "<br>" end if
Muligvis langt fra sådan, men noget i den stil mener jeg, at jeg har set det før. Leder i mens nogen har et svar :)
Det hjælper desværre ikke. Min tabel er 455 i bredden, og jeg lagde følgende kode ind:
#td1 { white-space: normal; width:455;}
og lagde en id="td1" i min TD.
Men min tekst med sindsyg mange tegn fortsætter langt ud, så jeg bliver nød til at scroll til højre for at se det hele, hvilket ikke burde være meningen.
Det skal lige siges, at den kun fortsætter, hvis det er 1 langt ord.
F.eks.: kkkkkkkkkkkkkkkk... bare 1000 flere K'er, så fortsætter den. Men hvis det er ord med mellemrum, så hopper den automatisk ned på næste linje f.eks:
dette er en test, også kopir den 100 gange.
En vigtig detalje, da den opfører sig som den skal, bare ikke med 1 langt sammensat ord.
- Det er i forhold til spam, så man ikke ødelægger siden ved at skrive noget sammensat.
Jeg bruger denne funktion, som jeg fandt på et tidspunkt. Du kan jo se om den kan klarer opgaven...
'------------------------------------------------------------------------------ ' WordWrap, author: Pete Nelson weasel@ecis.com ' ' Parameters : ' strWords - Words to add wrapping to ' intWrapLength - Length of each "line" ' str WrapText - Text to wrap words with, such as <br> or vbCrLf ' blnReplaceVbCrLf - True/False, remove vbCrLf from strWords? ' ' Purpose : ' Returns a string embedded with the strWrapText character, depending ' on intWrapLength. Used to insert vbCrLf or <br> in large amounts of ' text for better formatting ' '------------------------------------------------------------------------------
Function NewWordWrap(ByVal strWords, ByVal intWrapLength, ByVal strWrapText, ByVal blnReplaceVbCrLf)
Dim arrWords, arrTrailingCharacters, x Dim intRunningLength
'*** Strip out carriage returns If blnReplaceVbCrLf Then strWords = Replace(strWords, vbCrLf, " ") End If
'*** Split the words into an array using a space. The '*** second array just makes it easier to add the Wrap Text arrWords = Split(strWords, " ") arrTrailingCharacters = Split(strWords, " ")
'*** Set the trailing characters for each word to a space For x = LBound(arrTrailingCharacters) To UBound(arrTrailingCharacters) arrTrailingCharacters(x) = " " Next
'*** Now start looping through the words and adding the wrap text intRunningLength = 0
For x = LBound(arrWords) To UBound(arrWords)
'*** Calculate the running length of the words intRunningLength = intRunningLength + Len(arrWords(x) & " ")
'*** If we're at the exact word wrap length, add the wrapping text '*** at the end of the current word and reset the running length If intRunningLength = intWrapLength Then arrTrailingCharacters(x) = strWrapText intRunningLength = 0 End If
'*** If we've pass the wrapping length, put the wrapping text '*** at the end of the previous word. Set the running length '*** to the length of the current word. If intRunningLength >= intWrapLength And x > 0 Then arrTrailingCharacters(x - 1) = strWrapText intRunningLength = Len(arrWords(x) & " ") End If
Next
'*** Build the words and the wrapping text back together and return them For x = LBound(arrWords) To UBound(arrWords) NewWordWrap = NewWordWrap & arrWords(x) & arrTrailingCharacters(x) Next
Hej Kgkg. Jeg har først set dit svar nu, og har helt glemt spørgsmålet. Jeg lagde en lås på, så man max kunne skrive 300 tegn, da mere i princippet er ligegyldig.
Men smid svar så får du point. Kan se ved hurtigt at skimte det kode du postede, at det er i den retning. Så mon ikke jeg får brug for det på et tidspunkt ? :) (Nu ved jeg hvert fald hvor det er)
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.