|
-
Jan 22nd, 2003, 12:49 PM
#1
Thread Starter
Frenzied Member
Break String after 80 chars
I need to write a function that checks the len of a string.
if the length of the string is > than 80 characters then find the nearest space and break the line there, continuing to check if the remainder of the string is > than 80 characters, and so on.
pseudocode
Code:
if(Len(request("comments")) > 80) then
if(80th char in string is space) then
break to a new line and write the rest of the string
also checking if remainder of string is > than 80 if it is
then repeat
else
look backwards in the string to find a space and break it there
also checking if remainder of string is > than 80 if it is
then repeat
end if
else
response.write(request("comments"))
end if
any help would be appreicated.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jan 22nd, 2003, 01:21 PM
#2
Junior Member
Sorry this is a pretty scattered, but I've got to go, and I figure it's a start.
Basically,
-check to the length, and if there are spaces, first
-create an array to hold your resulting strings,
-create two pointers, one at the beginning of the string you are looking at, moving after each chunk is cut off, the other is at the end of the chunk you are looking at, moving left, looking for a space.
-create a pointer to where you are in the array
-take each chunk, find a space, or force a hyphen, put it into the array, move the left pointer to the right pointers old position and the right pointer forward 80, move the array pointer forward one
-repeat until the left pointer is within 80 chars of the end of the string, and then just take the rest
'Check to make sure strString01 is 80 chars first
if len(strString01)>79 then
'Create an array to hold the final values
intTemp01 = Cint(len(strString01)/80)
dim arrArray(intTemp01)
do while (len(strString01) - intCounterLeft)>80
if mid(strString01, 80, intCounterLeft) = chr(64) then
else
'Check to see if there is a Space in the String
'and where it is, from the right midpoint in the String
lngTemp01 = InstrRev(strString01, chr(64), intCounterRight)
if 'if theres no space' end if
'Put the result in the array
arrArray(intArrayCounter) = mid(strString01, intCounterLeft, lngTemp01)
end if
end if
loop
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|