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 January 9th, 2007, 09:37 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default remove returns

I have pretty standard code...

I have a textarea that gathers a comment.
I request the textarea
I put the text into a database.

I would like to remove any carriage returns that a user would enter in the textarea and replace them with a space before it goes into the db.
I've tried all the basics, "replace" vbCR, char(13), etc.
I can't seem to get the right comparison to find the return?
Any help here?

 
Old January 9th, 2007, 10:10 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

Have you tried removing char(10)? A carriage return is char(13) but when you hit the 'enter' button there are 2 chars that you have to deal with: char(13) which is a carriage return and char(10) which is a line feed. Try that.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old January 9th, 2007, 10:15 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

I use this function everytime I insert a block of text from a textarea:

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

That will place a <br> in place of a carriage return (replace the '<br>' with a " " to put a space there)

Place:
trim(storeText(request.form("heading")))
in your insert or update statement to use the function

Wind is your friend
Matt
 
Old January 9th, 2007, 10:24 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

here is the actual SQL snippet

'" & REPLACE(REPLACE(comments, "'", "''"), "char(10)", " ") & "'

char(10) didn't work,

I'm going to try Mat's function next.

 
Old January 9th, 2007, 10:28 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

That function does other useful things also, I assume you can follow them?

If you want to place a space instead of a <br> change:
StoreText = Replace(StoreText, vbCrLf, "<BR>", 1, -1, 1)
to
StoreText = Replace(StoreText, vbCrLf, " ", 1, -1, 1)


Wind is your friend
Matt
 
Old January 9th, 2007, 10:33 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok,
Modified the sql statement to this

'" & trim(storeText(comments)) & "',

with Mat's function, SOOOOO close....when I feed it back to a textarea on an editing page I get:

a<BR>b<BR>c

In the text box.....this is close!

 
Old January 9th, 2007, 10:36 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Bingo:)

Funny...I reread the code before you posted the <br>:D

Put in the space....worked like a charm.
Thanks so much...Yes I looked over the code...VERY useful function...going to hang on to that one!

Thanks again!

Red

 
Old January 9th, 2007, 10:43 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

When you display it use the following function:

  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

Fired like:
<Td><%= trim(displayMemo(rs("fieldName"))) %></td>

Wind is your friend
Matt
 
Old January 9th, 2007, 10:50 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

The function above is to display the info in a table cell. use this one to display it in a text area:

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

fired like:
<textarea>DisplayRMemo(trim(getInfo(5)))</textarea>

Wind is your friend
Matt
 
Old January 9th, 2007, 11:12 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got it to display correctly in the textarea(I think)

But I have another question.....I literally copied and pasted this code

 <TABLE style="WIDTH: 574px; HEIGHT: 96px; BACKGROUND-COLOR: lightsteelblue"
cellSpacing=1 cellPadding=1 width=574 border=1>

  <TR>
    <TD><STRONG>Comments:</STRONG></TD>
    <TD><TEXTAREA id=TEXTAREA1 onkeydown=limitText(this.form.comments,this.form.c ountdown,255); onkeyup=limitText(this.form.comments,this.form.cou ntdown,255); style="WIDTH: 466px; HEIGHT: 47px" name=comments rows=1 cols=49></TEXTAREA>

(Maximum characters: 255)<br>
You have <input readonly name="countdown" size="3" value="255"
           > characters left.

    </TD></TR></TABLE>
        <p>
          <INPUT id=submit1 type=submit value="Add Camera" name=submit1>
          <STRONG>&nbsp;&nbsp; </STRONG>
          <INPUT id=reset1 type=reset value=Reset name=reset1>
        </p>
    </form></td>
  </tr>
</table>
</body>
</html>

I feed the db value back in with =rs.fields......
but I get different behavior...on the original form I can hit return and keep typing.
On the edit page with exactly the same code when I hit enter in the textarea it submits?






Similar Threads
Thread Thread Starter Forum Replies Last Post
ReadProcessMemory returns nothing evolution445 Visual Basic 2005 Basics 17 October 8th, 2008 07:56 AM
for-each carriage returns TiLaser XSLT 4 April 28th, 2008 07:31 PM
Not all code returns a value Doom C# 4 February 11th, 2008 03:48 PM
using() in a method that returns.... belphoebes_friend General .NET 1 April 12th, 2007 04:41 PM
Remove Hard Returns from Memo Field darinsee Classic ASP Databases 4 July 7th, 2004 04:08 PM





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