Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2008, 04:22 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stripping CRLF??

I need to strip out the CR and LF from a comment field before displaying it. How is this done?

I've tried:

comment = replace(comment,"CHAR(13)&CHAR(10)","")
comment = replace(comment,CHAR(13)&CHAR(10),"")
comment = replace(comment,"CHAR(13)"&"CHAR(10)","")
comment = replace(comment,"vbCRLF","")
comment = replace(comment,vbCRLF,"")

Nothing works... How is it done??

Thanks.

 
Old February 23rd, 2008, 05:09 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

These are normally replaced with <br>'s if you are displaying the text. Is this what you are trying to do? If so this does it for me:

  Function DisplayMemo(theText)
    DisplayMemo = ""
    on error resume next
    DisplayMemo = CStr(theText)
    if (len(DisplayMemo) > 0) Then
      DisplayMemo = Replace(DisplayMemo, vbCrLf, "<br>", 1, -1, 1)
    end if
  End Function

If not im sure you can alter the function to do what you want it to do.
Additionaly - I wrap this function when inserting to the DB:

  Function StoreText(theText)
    StoreText = ""
    on error resume next
    StoreText = CStr(theText)
    if (len(StoreText) > 0) Then
      StoreText = Replace(StoreText, """", "&quot;", 1, -1, 1)
      StoreText = Replace(StoreText, "'", "''", 1, -1, 1)
      StoreText = Replace(StoreText, vbCrLf, "<BR>", 1, -1, 1)
    end if
  End Function

Wind is your friend
Matt
www.elitemarquees.com.au
 
Old February 25th, 2008, 10:35 AM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm trying to store the comment in SQL without the CRLF. The reason this. I have a edit form that pulled the data from SQL, and using Javascript, it autofills the edit form.

The problem happens because of the javascript. When there's a linebreak from the CRLF, the Javascript bombs. :( So I figure, I'll just store the comment data without the CRLF.

 
Old February 25th, 2008, 01:12 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've got good news... I pretty much gave up and was going to look at a Javascript option, but I decided to try comment = replace(comment,vbCRLF,"") again and it worked....

 
Old February 25th, 2008, 05:31 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

mmmmm I dont get it.

IMO - If a user enters a line break (vbCRLF) and hits submit why would you replace it with an empty string? If I was a user of on your site and took the time to enter information, I would be annoyed coming back to see my linebreaks removed.

Wind is your friend
Matt
www.elitemarquees.com.au
 
Old February 25th, 2008, 05:35 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I agree with Matt. If I were to follow the solution you have provided for this text:

This is the first line of my comment.
This is the second line of my comment.

When I go to write that back out to the browser it is going to look like this:

This is the first line of my comment.This is the second line of my comment.

Maybe I have misunderstood something?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 26th, 2008, 03:08 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The reason I had to take the line breaks out was because when of Javascript.

I have this script that auto fills a form for editing purposes. Well when the Javascript saw the line break, it would bomb. Plus the comment is short so it won't really be an issue. The biggest problem I had was at the end of the comment, people would insert a line break.

 
Old February 26th, 2008, 05:58 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Personally I would never do this with JS. You have highlighted one of the, IMO many reasons why. ASP does a fine job of populating forms...

My 2 cents worth:
mmmm, strange user behaviour. I dont experience people hitting enter after entering data into text areas. If I did I and wanted to get rid of this last carridge return i would strip it off before inserting it into the DB. I wouldnt ever recommend removing all of the returns like your replace syntax is sure to do.

Wind is your friend
Matt
www.elitemarquees.com.au





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stripping last X characters fixxer XSLT 2 September 21st, 2007 05:11 PM
Stripping hyphens arholly Access 2 January 4th, 2007 09:16 AM
regex for stripping space muki XSLT 2 February 8th, 2006 06:29 AM
Stripping down variable values mellan XSLT 1 September 19th, 2005 09:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.