Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Reverse text

Reply
Thread Tools

Reverse text

 
 
Steven Burn
Guest
Posts: n/a
 
      01-07-2004
Just wondering if anyone is aware of any way to reverse the following so it
displays the text from

end of file > start of file

instead of

start of file > end of file


<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim ThisLine
Dim PrintLine
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
SomeFile = Server.MapPath("somefile.txt")
Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
Do While Not InputStream.AtEndOfStream
ThisLine = InputStream.ReadLine
PrintLine = PrintLine + ThisLine + "<br>"
Loop
InputStream.Close
Set OutputStream = Nothing
Set FileObject = Nothing
Response.Write PrintLine
%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)



 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      01-07-2004
Do you mean that the last line goes first still preserving the prder od
letters in it, or you want the last letter of the file to come first and so
on?

"Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
news:(E-Mail Removed)...
> Just wondering if anyone is aware of any way to reverse the following so

it
> displays the text from
>
> end of file > start of file
>
> instead of
>
> start of file > end of file
>
>
> <%
> Const ForReading = 1, ForWriting = 2, ForAppending = 8
> Dim ThisLine
> Dim PrintLine
> Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
> SomeFile = Server.MapPath("somefile.txt")
> Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
> Do While Not InputStream.AtEndOfStream
> ThisLine = InputStream.ReadLine
> PrintLine = PrintLine + ThisLine + "<br>"
> Loop
> InputStream.Close
> Set OutputStream = Nothing
> Set FileObject = Nothing
> Response.Write PrintLine
> %>
>
> --
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
> Disclaimer:
> I know I'm probably wrong, I just like taking part ;o)
>
>
>



 
Reply With Quote
 
 
 
 
Steven Burn
Guest
Posts: n/a
 
      01-07-2004
Basically, the file contains comments such as below;

Date
Name
E-mail
Website
Comments

(see example at:
http://www.it-mate.co.uk/support/gue...wguestbook.asp)

At present, the oldest is shown first (i.e. the first entry in the file) as
newer one's are simply appended to the file, so are thus, shown last (the
oldest entry being at the top of the page, and the newest, at the bottom).

I simply want to reverse the order in which the entries are shown, so the
newest is at the top, and the oldest, at the bottom. (if that makes sense?).

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)


<aa> wrote in message news:(E-Mail Removed)...
> Do you mean that the last line goes first still preserving the prder od
> letters in it, or you want the last letter of the file to come first and

so
> on?
>
> "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
> news:(E-Mail Removed)...
> > Just wondering if anyone is aware of any way to reverse the following so

> it
> > displays the text from
> >
> > end of file > start of file
> >
> > instead of
> >
> > start of file > end of file
> >
> >
> > <%
> > Const ForReading = 1, ForWriting = 2, ForAppending = 8
> > Dim ThisLine
> > Dim PrintLine
> > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
> > SomeFile = Server.MapPath("somefile.txt")
> > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

False)
> > Do While Not InputStream.AtEndOfStream
> > ThisLine = InputStream.ReadLine
> > PrintLine = PrintLine + ThisLine + "<br>"
> > Loop
> > InputStream.Close
> > Set OutputStream = Nothing
> > Set FileObject = Nothing
> > Response.Write PrintLine
> > %>
> >
> > --
> > Regards
> >
> > Steven Burn
> > Ur I.T. Mate Group
> > www.it-mate.co.uk
> >
> > Keeping it FREE!
> >
> > Disclaimer:
> > I know I'm probably wrong, I just like taking part ;o)
> >
> >
> >

>
>



 
Reply With Quote
 
TomB
Guest
Posts: n/a
 
      01-07-2004
PrintLine should contain the entire file, so you should be able to .....

Dim iLoop
Dim ReversedPrintLine
for iLoop = len(PrintLine) to 1 step-1
ReversedPrintLine=ReversedPrintLine & Mid(PrintLine,iLoop,1)
next

I'm assuming somefile.txt is text.

"Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
news:(E-Mail Removed)...
> Just wondering if anyone is aware of any way to reverse the following so

it
> displays the text from
>
> end of file > start of file
>
> instead of
>
> start of file > end of file
>
>
> <%
> Const ForReading = 1, ForWriting = 2, ForAppending = 8
> Dim ThisLine
> Dim PrintLine
> Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
> SomeFile = Server.MapPath("somefile.txt")
> Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
> Do While Not InputStream.AtEndOfStream
> ThisLine = InputStream.ReadLine
> PrintLine = PrintLine + ThisLine + "<br>"
> Loop
> InputStream.Close
> Set OutputStream = Nothing
> Set FileObject = Nothing
> Response.Write PrintLine
> %>
>
> --
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
> Disclaimer:
> I know I'm probably wrong, I just like taking part ;o)
>
>
>



 
Reply With Quote
 
TomB
Guest
Posts: n/a
 
      01-07-2004
I didn't think of that. You could do that (reverse line order but not
letters) by changing
PrintLine=PrintLine + ThisLine+"<BR>"
to
PrintLine=ThisLine+PrintLine+"<BR>"

<aa> wrote in message news:(E-Mail Removed)...
> Do you mean that the last line goes first still preserving the prder od
> letters in it, or you want the last letter of the file to come first and

so
> on?
>
> "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
> news:(E-Mail Removed)...
> > Just wondering if anyone is aware of any way to reverse the following so

> it
> > displays the text from
> >
> > end of file > start of file
> >
> > instead of
> >
> > start of file > end of file
> >
> >
> > <%
> > Const ForReading = 1, ForWriting = 2, ForAppending = 8
> > Dim ThisLine
> > Dim PrintLine
> > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
> > SomeFile = Server.MapPath("somefile.txt")
> > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

False)
> > Do While Not InputStream.AtEndOfStream
> > ThisLine = InputStream.ReadLine
> > PrintLine = PrintLine + ThisLine + "<br>"
> > Loop
> > InputStream.Close
> > Set OutputStream = Nothing
> > Set FileObject = Nothing
> > Response.Write PrintLine
> > %>
> >
> > --
> > Regards
> >
> > Steven Burn
> > Ur I.T. Mate Group
> > www.it-mate.co.uk
> >
> > Keeping it FREE!
> >
> > Disclaimer:
> > I know I'm probably wrong, I just like taking part ;o)
> >
> >
> >

>
>



 
Reply With Quote
 
Steven Burn
Guest
Posts: n/a
 
      01-07-2004
It's plain text yes but, unfortunately I've tried that and it reverses the
order of the entries aswell (see my reply to aa's reply).

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)


TomB <(E-Mail Removed)> wrote in message
news:uczm$(E-Mail Removed)...
> PrintLine should contain the entire file, so you should be able to .....
>
> Dim iLoop
> Dim ReversedPrintLine
> for iLoop = len(PrintLine) to 1 step-1
> ReversedPrintLine=ReversedPrintLine & Mid(PrintLine,iLoop,1)
> next
>
> I'm assuming somefile.txt is text.
>
> "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
> news:(E-Mail Removed)...
> > Just wondering if anyone is aware of any way to reverse the following so

> it
> > displays the text from
> >
> > end of file > start of file
> >
> > instead of
> >
> > start of file > end of file
> >
> >
> > <%
> > Const ForReading = 1, ForWriting = 2, ForAppending = 8
> > Dim ThisLine
> > Dim PrintLine
> > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
> > SomeFile = Server.MapPath("somefile.txt")
> > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

False)
> > Do While Not InputStream.AtEndOfStream
> > ThisLine = InputStream.ReadLine
> > PrintLine = PrintLine + ThisLine + "<br>"
> > Loop
> > InputStream.Close
> > Set OutputStream = Nothing
> > Set FileObject = Nothing
> > Response.Write PrintLine
> > %>
> >
> > --
> > Regards
> >
> > Steven Burn
> > Ur I.T. Mate Group
> > www.it-mate.co.uk
> >
> > Keeping it FREE!
> >
> > Disclaimer:
> > I know I'm probably wrong, I just like taking part ;o)
> >
> >
> >

>
>



 
Reply With Quote
 
Curt_C [MVP]
Guest
Posts: n/a
 
      01-07-2004
use two strings....
one to hold the person, one to hold the group.
Read in the Person info assigning it like
stringPer = stringPer + moreinfo

When each person is done assign it to the group string like this
stringGrp = stringPer + stringGrp
stringPer = "" (make sure to reset the stringPer each time)



--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com


"Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
news:(E-Mail Removed)...
> Basically, the file contains comments such as below;
>
> Date
> Name
> E-mail
> Website
> Comments
>
> (see example at:
> http://www.it-mate.co.uk/support/gue...wguestbook.asp)
>
> At present, the oldest is shown first (i.e. the first entry in the file)

as
> newer one's are simply appended to the file, so are thus, shown last (the
> oldest entry being at the top of the page, and the newest, at the bottom).
>
> I simply want to reverse the order in which the entries are shown, so the
> newest is at the top, and the oldest, at the bottom. (if that makes

sense?).
>
> --
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
> Disclaimer:
> I know I'm probably wrong, I just like taking part ;o)
>
>
> <aa> wrote in message news:(E-Mail Removed)...
> > Do you mean that the last line goes first still preserving the prder od
> > letters in it, or you want the last letter of the file to come first and

> so
> > on?
> >
> > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
> > news:(E-Mail Removed)...
> > > Just wondering if anyone is aware of any way to reverse the following

so
> > it
> > > displays the text from
> > >
> > > end of file > start of file
> > >
> > > instead of
> > >
> > > start of file > end of file
> > >
> > >
> > > <%
> > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
> > > Dim ThisLine
> > > Dim PrintLine
> > > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
> > > SomeFile = Server.MapPath("somefile.txt")
> > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

> False)
> > > Do While Not InputStream.AtEndOfStream
> > > ThisLine = InputStream.ReadLine
> > > PrintLine = PrintLine + ThisLine + "<br>"
> > > Loop
> > > InputStream.Close
> > > Set OutputStream = Nothing
> > > Set FileObject = Nothing
> > > Response.Write PrintLine
> > > %>
> > >
> > > --
> > > Regards
> > >
> > > Steven Burn
> > > Ur I.T. Mate Group
> > > www.it-mate.co.uk
> > >
> > > Keeping it FREE!
> > >
> > > Disclaimer:
> > > I know I'm probably wrong, I just like taking part ;o)
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Steven Burn
Guest
Posts: n/a
 
      01-07-2004
Cheers Curt, I'll give it a shot ;o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)


Curt_C [MVP] <software_AT_darkfalz.com> wrote in message
news:#(E-Mail Removed)...
> use two strings....
> one to hold the person, one to hold the group.
> Read in the Person info assigning it like
> stringPer = stringPer + moreinfo
>
> When each person is done assign it to the group string like this
> stringGrp = stringPer + stringGrp
> stringPer = "" (make sure to reset the stringPer each time)
>
>
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> www.Darkfalz.com
>
>
> "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
> news:(E-Mail Removed)...
> > Basically, the file contains comments such as below;
> >
> > Date
> > Name
> > E-mail
> > Website
> > Comments
> >
> > (see example at:
> > http://www.it-mate.co.uk/support/gue...wguestbook.asp)
> >
> > At present, the oldest is shown first (i.e. the first entry in the file)

> as
> > newer one's are simply appended to the file, so are thus, shown last

(the
> > oldest entry being at the top of the page, and the newest, at the

bottom).
> >
> > I simply want to reverse the order in which the entries are shown, so

the
> > newest is at the top, and the oldest, at the bottom. (if that makes

> sense?).
> >
> > --
> > Regards
> >
> > Steven Burn
> > Ur I.T. Mate Group
> > www.it-mate.co.uk
> >
> > Keeping it FREE!
> >
> > Disclaimer:
> > I know I'm probably wrong, I just like taking part ;o)
> >
> >
> > <aa> wrote in message news:(E-Mail Removed)...
> > > Do you mean that the last line goes first still preserving the prder

od
> > > letters in it, or you want the last letter of the file to come first

and
> > so
> > > on?
> > >
> > > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
> > > news:(E-Mail Removed)...
> > > > Just wondering if anyone is aware of any way to reverse the

following
> so
> > > it
> > > > displays the text from
> > > >
> > > > end of file > start of file
> > > >
> > > > instead of
> > > >
> > > > start of file > end of file
> > > >
> > > >
> > > > <%
> > > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
> > > > Dim ThisLine
> > > > Dim PrintLine
> > > > Set FileObject =

Server.CreateObject("Scripting.FileSystemObject")
> > > > SomeFile = Server.MapPath("somefile.txt")
> > > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

> > False)
> > > > Do While Not InputStream.AtEndOfStream
> > > > ThisLine = InputStream.ReadLine
> > > > PrintLine = PrintLine + ThisLine + "<br>"
> > > > Loop
> > > > InputStream.Close
> > > > Set OutputStream = Nothing
> > > > Set FileObject = Nothing
> > > > Response.Write PrintLine
> > > > %>
> > > >
> > > > --
> > > > Regards
> > > >
> > > > Steven Burn
> > > > Ur I.T. Mate Group
> > > > www.it-mate.co.uk
> > > >
> > > > Keeping it FREE!
> > > >
> > > > Disclaimer:
> > > > I know I'm probably wrong, I just like taking part ;o)
> > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      01-07-2004
"Steven Burn" wrote:
>
> Just wondering if anyone is aware of any way to reverse
> the following so it displays the text from
>
> end of file > start of file
>
> instead of
>
> start of file > end of file


I assume you mean one line at a time. If the file isn't too large, string
concatenation shouldn't be too taxing on VBScript. Replace these two
lines...

ThisLine = InputStream.ReadLine
PrintLine = PrintLine + ThisLine + "<br>"

....with this:
PrintLine = InputStream.ReadLine() + "<br>" + PrintLine


In general, reversal of order is a great job for a stack. JScript lets you
treat any array like one. Then again, it has a reverse() method. For
completeness, here is a JScript alternative to string concatenation:

var a = new Array(), forReading = 1,
fso = Server.CreateOject("Scripting.FileSystemObject"),
file = fso.OpenTextFile("somefile.txt", forReading)
while (!file.AtEndOfStream) a.push(file.ReadLine())
file.Close()

At this point, you can either use Array.reverse()...
Response.Write(a.reverse().join("<BR>"))

....or a sequence of Array.pop() operations:
while (a.length) Response.Write(a.pop() + "<BR>")



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


 
Reply With Quote
 
Guest
Posts: n/a
 
      01-07-2004
Yes, It makes sense.
The cleanest way seems to use a database rather then a text file - you will
get much greater freedom of presentation the data.
Another option is to use XML rather then flat text
Alternatively you can read the lines into an array and then output the array
starting with the highest index
"Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
news:(E-Mail Removed)...
> Basically, the file contains comments such as below;
>
> Date
> Name
> E-mail
> Website
> Comments
>
> (see example at:
> http://www.it-mate.co.uk/support/gue...wguestbook.asp)
>
> At present, the oldest is shown first (i.e. the first entry in the file)

as
> newer one's are simply appended to the file, so are thus, shown last (the
> oldest entry being at the top of the page, and the newest, at the bottom).
>
> I simply want to reverse the order in which the entries are shown, so the
> newest is at the top, and the oldest, at the bottom. (if that makes

sense?).
>
> --
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
> Disclaimer:
> I know I'm probably wrong, I just like taking part ;o)
>
>
> <aa> wrote in message news:(E-Mail Removed)...
> > Do you mean that the last line goes first still preserving the prder od
> > letters in it, or you want the last letter of the file to come first and

> so
> > on?
> >
> > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
> > news:(E-Mail Removed)...
> > > Just wondering if anyone is aware of any way to reverse the following

so
> > it
> > > displays the text from
> > >
> > > end of file > start of file
> > >
> > > instead of
> > >
> > > start of file > end of file
> > >
> > >
> > > <%
> > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
> > > Dim ThisLine
> > > Dim PrintLine
> > > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
> > > SomeFile = Server.MapPath("somefile.txt")
> > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

> False)
> > > Do While Not InputStream.AtEndOfStream
> > > ThisLine = InputStream.ReadLine
> > > PrintLine = PrintLine + ThisLine + "<br>"
> > > Loop
> > > InputStream.Close
> > > Set OutputStream = Nothing
> > > Set FileObject = Nothing
> > > Response.Write PrintLine
> > > %>
> > >
> > > --
> > > Regards
> > >
> > > Steven Burn
> > > Ur I.T. Mate Group
> > > www.it-mate.co.uk
> > >
> > > Keeping it FREE!
> > >
> > > Disclaimer:
> > > I know I'm probably wrong, I just like taking part ;o)
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: reverse text VanguardLH Computer Support 0 05-05-2009 04:55 PM
Re: reverse text Evan Platt Computer Support 0 05-05-2009 03:00 PM
How to reverse text in WordPerfect 11? DaveF Computer Support 11 07-09-2006 03:06 PM
reading large text files in reverse - optimization doubts Rajorshi Biswas C Programming 6 09-28-2005 07:10 AM
Stacks Queues Reverse Reverse Polish dogbite C++ 4 10-10-2003 05:06 AM



Advertisments