View Full Version : Char length String manipulation?
hi there
Does any one know how i could do this?
I have an article in my database which is 10,000 char long.
I want to display it on the page but i want to show it in 5 parts so i gett he first 2000 characters on the screen and then a continue button and then the next 2000 characters and so on.
I think you can do it by telling the page i want to see the first 2000char of the string and then have the next lot of text saying dont show the first 2000 but start at char 2001.
Then have a bit of code that sees if the char start at 1 then show continue if char start 2001 show continue and back and if char start 8001 then show back.
is this possible if so can anybody show me an example of the code i would need to add to the normal <%recordset("text")%> tags so to get it to work.
I am hoping this can be done on one page so that their is no need to reload the page as the string value is in place when it loads so i the page shouldn't need to reload i think. if it does then that is not a problem.
Any idea's welcome?????:confused: :confused: :confused:
Get the first 2000 characters? --> Left(recordset("text"),2000)
But this will chop it off quite brutally. Like :" ...Human existence comes down to e"
If you need to get it in chunks of 2000 characters, i'd post the page to itself, and have some sort of ofset (=last printed character+1) that is appended to the querystring or stored in a hidden formfield. The code will then be something like:
If Len(request.form("ofset")) <> 0 then
ofset = request.form("ofset")
else
ofset = 0
end if
string = Right(recordset("text"), Len(recordset("text"))-ofset)
string = Left(string,2000)
ofset = ofset + 2000
The first time the page is loaded, you'll get from 0 to 2000 (ofset will be empty). Second time, you'll get from 2001 to 4000 etc etc.
Without reloading the page --> probably with some javascript, but i'm not that good at it (+ not everyone has javascript enabled)
you have got the idea spot on.
the idea is if someone sticks a monsterously long peice of text in which would strecth the page to a silly length this way the page will only show a manageable amount of text in each section.
Your right about it blunting the ned of he text when it hits 2000 characters. is their any way to get it to start looking at 2000 for the next <P> tag as this will safely cut the text off at the end of the paragh it is on. then how do you get it set the of set to this so the next block of text starts after the <P> so the next page starts where the prievous one ended.
Also for the next button what would the condition region be if ofset < 2500 then next nutton else back button and next image
the back button having a javascript back 1 page to bring the previous text back and the next button simply having a refresh action on it
Do you think this is possible if so can you give me an idea of what code i will need to be playing with to get this to work.
:confused: :thumbsup: :confused: :thumbsup: :confused: :thumbsup:
is their any way to get it to start looking at 2000 for the next <P> tag as this will safely cut the text off at the end of the paragh it is on
Yes. Use InStr, starting from 1950 or something to find the first following <p> position (i don't know if it'l take the first character or so, so you might want to do some counting, and possibly adding 1 or 2 to the cutof (to get the full <p> to print)
cutof = Instr(1950, recordset("variable"), "<p>", 1)
(+ maybe
cutof = cutof + 2 )
Then, to get the part to display:
print = Left(recordset("variable"), cutof)
This cutofvalue then should be added to the page (in a hidden field, or, added to the querystring for the buttons. Each time the page loads (whether they refresh it or go back or forth, the value for the cutofvaluevariable is used in the routine as ofset to find the next pages cutof on <p> position
string = Right(recordset("text"), Len(recordset("text"))-request.querystring("cutof"))
cutof = Instr(1950, recordset("variable"), "<p>", 1)
print = Left(recordset("variable"), cutof)
cutof = cutof + request.querystring("cutof")
So each time the page is loaded, the part that has allready been displayed, is first removed, and then the next chunk of around 2000 characters is searched.
on the next button, you need to add the value of the cutof variable (to the querystring --> blabla.asp?cutof=<%=cutof%>)
To go back. hmm.
Think this could probably be solved best building an array that you store in a sessionvariable. On top of each page, the value from the querystring should be stored in the array (or fist be compaired with the last value to avoid duplicates) Then you could build a menu withlinks to page 1, page 2 ... and get the cutof value for the querystring from the array. --> page 1 should be array(0), page 2 should be array(1), ... but you will need to add an additional variable to the querystring that indicates it's a back-navigation, so the code would be something like
string = Right(recordset("text"), Len(recordset("text"))-request.querystring("cutof"))
cutof = Instr(1950, recordset("variable"), "<p>", 1)
print = Left(recordset("variable"), cutof)
if request.querystring("action") <> "back" then
cutof = cutof + request.querystring("cutof")
end if
No ?
arnyinc
05-09-2003, 04:07 PM
I don't like when websites split up articles. I'd rather it be in one long page since I find it easier to read that way, and especially in case I want to print it.
Of course every situation is unique and someone is always going to complain. I'm just glad I got to be the one. :p
Like someones sig here said:
"It's not ours to ask why, just code and die"
Never used it myself but i can imagen some situations where it could be usefull. Say you use floatingboxes to show part of the content, and you want to keep them relatively small but without scrolbars or so ...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.