Solved

Textstream - adding new lines, tabs, etc.

Posted on 2004-10-16
5
333 Views
Last Modified: 2012-08-14
I create a textstream in my ASP page and read in a text file. In this text file is an email confirmation standard message, with also the text #ORDERINFO# in it somewhere. What I do once I have read in the text file is to loop through the order info then build a piece of text named orderstxt which has the order details in it. I then replace #ORDERINFO# with orderstxt. The problem is building orderstxt because I can't figure out how to add newlines, tabs, etc.

For example...

For i=0 to ubound(CCcart,2)
      if CCcart(CC_PRODUCTID,i) <> "" then
            orderstxt = orderstxt & "\n " & CCcart(CC_ProductID,i)
      end if
Next

...just puts "\n " into the text instead of creating a newline. Should I be using ASCII characters? I don't understand if what I'm reading in is ASCII, Unicode, etc.
0
Comment
Question by:ma701sss
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:minichicken
ID: 12327835
Where are you adding orderstxt to? To the DB or output it to a browser or to a plain text file?

Can you provide an exmaple, of the input and the output.... thanks

Are you looking for a string replace function like this (from w3school):

dim txt
txt="This is a beautiful day!"

document.write(Replace(txt,"beautiful","horrible"))

Output:This is a horrible day!
0
 

Author Comment

by:ma701sss
ID: 12327908
My text file has this in it:

<--BEGIN-->
Thanks for your order!

We have pleasure in confirming your order below.

#ORDERINFO#

Please allow 2 to 3 days for your order to arrive.
<--END-->

I then read in to a textstream the text file above. I then want to take the items ordered from the shopping cart and loop through them, adding newline and tab characters, and placing them into the variable orderstxt. The text in #ORDERINFO# is then replaced with orderstxt. I then take the textstream and use it as the body in a CDONTS message, and email it to the customer.
0
 
LVL 12

Accepted Solution

by:
minichicken earned 100 total points
ID: 12327918
If it's going into the DB then I would recommend use of ASCII - chr(13) for "ENTER or New line" and chr(9) for "TAB"

For i=0 to ubound(CCcart,2)
     if CCcart(CC_PRODUCTID,i) <> "" then
          orderstxt = orderstxt & chr(13) & CCcart(CC_ProductID,i)
     end if
Next

When you want to retrive it from the DB and display with the new lines and tabs
you will need to use the Replace function

e.g. Replace(orderstxt_from_db, chr(13), "<br>") 'this replaces "ENTER" with line break in HTML

regards-
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12327968
Oh ok...

Now, I understand, I think.....

If your email body is PLAIN TEXT then you will use "\n" and If your email body is HTML then you will need to use "<br>" for "new line".
For TAB, you can use "\t" in PLAIN TEXT but don't think there is TAB in HTML, so you might need to use &nbsp; (non breaking space) instead.

Inserting "new line"

PLAIN TEXT----------------------------------------------------------
For i=0 to ubound(CCcart,2)
     if CCcart(CC_PRODUCTID,i) <> "" then
          orderstxt = orderstxt & "\n " & CCcart(CC_ProductID,i)
     end if
Next

HTML -----------------------------------------------------------------

For i=0 to ubound(CCcart,2)
     if CCcart(CC_PRODUCTID,i) <> "" then
          orderstxt = orderstxt & "<br>" & CCcart(CC_ProductID,i)
     end if
Next

Insert TAB

PLAIN TEXT----------------------------------------------------------
For i=0 to ubound(CCcart,2)
     if CCcart(CC_PRODUCTID,i) <> "" then
          orderstxt = orderstxt & "\t " & CCcart(CC_ProductID,i)
     end if
Next

HTML -----------------------------------------------------------------

For i=0 to ubound(CCcart,2)
     if CCcart(CC_PRODUCTID,i) <> "" then
          orderstxt = orderstxt & "&nbsp;&nbsp;&nbsp;" & CCcart(CC_ProductID,i)
     end if
Next
0
 

Author Comment

by:ma701sss
ID: 12328213
No, the "\t" doesn't work, as already mentioned.

Your suggestion of chr(9) and chr(13) works.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now