11. december 2000 - 13:23Der er
12 kommentarer og 1 løsning
Wordwrap på tekst fra textarea - HASTER!!!!
Hej!
Det skal bruges til en form for postkortservice på en webside. En kort-skabelon åbnes ved hjælp af AspImage 2.0, teksten fra formularen ligges ovenpå skabelonen, og derefter gemmes billedet med tekst til en ny jpg-fil. Teksten skal derfor have en max-bredde på f.eks. 100 pixels.
Da jeg ikke er den store asp-haj, kan jeg ikke selv lave wordwrap-funtionen. Er det nogen som gider hjælpe, eller bare har en idé om hvordan det skal laves?
Med version 7 af TeamShare tager Lector næste skridt og bygger en platform for AI-agenter, der i højere grad kan følge medarbejderen gennem hele arbejdsprocessen.
Det er lidt en umulig opgave da du ikke på nogen måde kan finde ud af hvor bredt hvert bogstav er. Det kan du kun vide hvis du bruger Courier New eller en anden non-proprotional (staves det ikke sådan !?) skrifttype... og så skal du selv finde ud af det...
Jeg fandt denne en dag da jeg skulle bruge en \"wrapper\". Håber den kan bruges.. ---------------------------------------------- <% \' This function allows you to choose a string and the number of characters to wrap at. It works \' in tables and other areas. \' \' Call with \' \' Bigtext(string,length) \' \' Where String is the string you wish to process, and length is the number of characters in a \' column to wrap at. It also turns null strings into \"\" blank strings to avoid invalid use of null \' errors. \' \' Word wrapping works most of the time, some words might get truncated, I am not sure why. \' It is a good start at building your own routine to wrap words. I estimate it wraps words 80% \' of the time, and the rest tend to cut them off. \' \' The next line is printed out as a BR tag, this is to display in tables. If you want to store in \' databases, you can replace this with CHR(13) & CHR(10) or VBCrLf instead. %> <% Function BigText(s_Text, i_Len) \' Prints out Big Text in small chunks Dim i_pos \' position in string Dim s_Temp Dim s_Line Dim i_space \'Location of Space
If Trim(\"\" & s_Text) <> \"\" Then \'Not Blank or Null s_Temp = \"\" i_pos = 1 \' Loop through and print out all of the text in case it is too long. Do While i_pos < Len(s_Text) \'While part we are looking at is less than the whole thing s_Line = Mid(s_Text,i_pos,i_Len) \'Get a line i_Len long i_space = i_Len \'Set i_space to i_len If Len(s_Line) = i_Len Then \'If i_Len characters, scan for a space If Right(s_Line,1) <> \" \" Then \'If last character is not a space, backup and find a non-space to wrap the word
Do While Mid(s_Line,i_space,1) <> \" \" \' If not space, back up until we hit the old position or a non-space i_space = i_space - 1 \'Go back one character s_Line = Mid (s_Text,i_pos,i_space) \'Refresh the line Loop If i_space = i_pos Then \' If we hit the last position, use the whole line s_Line = Mid(s_Text,i_pos,i_Len) i_space = i_Len End If End If End If s_Line = Mid(s_Text,i_pos,i_space) \'Refresh the line s_Temp = s_Temp & s_Line & \"<br>\" \'Add a CR/LF aka <BR> tag after the line
i_pos = i_pos + i_space \'Advance to the next i_space characters Loop BigText = s_Temp \'Set the function to the parsed out, word wrapped, line Else BigText = \" \" \'Must be blank or Null, make it a non-breaking space End If End Function %> ---------------------------------------
guro.net:> Her er mit forslag .. lidt mere simpelt end det du kom med .. men jeg aner ikke hvilken der er hurtigst .. *er lidt stolt af at jeg har lavet den .. har aldrig prøvet før .. *LOL**
<pre> <% Function Wrap(strString, intWrapAt) WrapChar = vbCrLf
\' \"\" & pga. suppresion af null. If Len(strString) < intWrapAt Then Wrap = \"\" & strString: Exit Function
Do If Len(strString) < intWrapAt Then strFinal = strFinal & strString: Exit Do
\' Hvis der hvor vi cutter er et mellemrum er vi home safe If Mid(strString, intWrapAt, 1) = \" \" Then strPart = Left(strString, intWrapAt) strString = Right(strString, Len(strString) - intWrapAt) strFinal = strFinal & strPart & WrapChar
\' Ikke ? Nå .. så prøver vi at finde et mellemrum bagud, hvis intet fundet så prøver \' vi at finde et foran der hvor vi ville cutte. Hvis heller intet; returnér hele strengen \' og afslut loopet. Else strPart = Left(strString, intWrapAt) intOff = InStrRev(strPart, \" \") If intOff = 0 Then intOff = InStr(strString, intWrapAt, \" \") If intOff = 0 Then strPart = strString strPart = Left(strString, intOff)
strString = Right(strString, Len(strString) - Len(strPart)) strFinal = strFinal & strPart & WrapChar End If Loop
Wrap = strFinal End Function
strStreng = \"dette er en lang streng som vi skal wordwrappe ned til max 50 tegn! Det burde gerne virker perfekt, men nu ser vi..\" Response.Write Wrap(strStreng, 29) %> </pre>
*lol* jeg troede der stod \"guro.net\" og ikke .not Men det var så lidt ..
Synes godt om
Ny brugerNybegynder
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.