SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    .net install meltdown
    Join Date
    May 2001
    Location
    View Ridge
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Respnose.Write & quotes

    Hey all,

    I'm sure this has come up before, but I couldn't find any old posts so here goes:

    I'm using a loop to write a series of links into the page.

    Code:
    While Not oRS.EOF
      Response.Write "<p><a href=" & oRS("FileName") & ".pdf target=_blank>" & oRS("JobTitle") & "</a></p>" &vblf
      oRS.MoveNext
    Wend
    I want to write the appropriate quotation marks around the href="" but can't figure out how to do it without an error. Do I have to break up the html & asp and use a seperate loop for each asp section or is there something easier?

  2. #2
    SitePoint Wizard big_al's Avatar
    Join Date
    May 2000
    Location
    Victoria, Australia
    Posts
    1,661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    While Not oRS.EOF
      Response.Write "<p><a href=""" & oRS("FileName") & ".pdf"" target=_blank>" & oRS("JobTitle") & "</a></p>" &vblf
      oRS.MoveNext
    Wend
    That should do the trick
    .NET Code Monkey

  3. #3
    .net install meltdown
    Join Date
    May 2001
    Location
    View Ridge
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well that worked!

    So, to write -"- its -""-. Its the little things that can drive ya bonkers.

    Thanks again big_al.

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, if your going to input stuff into a database, domething like

    don't

    will cause and error. The ' will cause it because it will think your closes the string, so you should write a function that makes all ' into ''


  5. #5
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I prefer to use Chr(x) for quotes and apostrophes, as it makes the code easier to read...


    Response.Write( "<a href=" & Chr(34) & "/this.xml" & Chr(34) & ">This XML</a>" )
    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  6. #6
    .net install meltdown
    Join Date
    May 2001
    Location
    View Ridge
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by dhtmlgod
    Also, if your going to input stuff into a database, domething like

    don't

    will cause and error. The ' will cause it because it will think your closes the string, so you should write a function that makes all ' into ''

    d,

    I'm not following you.

    Haven't tried writing to the database yet, but plan to once I get confident with some of the other aspects of asp. Can you clarify so I'll know when I get there?

  7. #7
    .net install meltdown
    Join Date
    May 2001
    Location
    View Ridge
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kode,

    I tried using &amp;quot; as well as &amp;#34;, but that just wrote those characters into the html:

    <a href="&quot;...

    From your post I'm guessing asp has an equivalent set of characters like the html ones?

    I'll try using the Chr(x) method, seems like that would make things less confusing esp. since I'm still in the early learning stages (can you tell?).

    Do you have a link to a reference on the Chr(x) characters or are they the same #'s as the html ones?
    Last edited by isotope235; Dec 5, 2001 at 20:07.

  8. #8
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem, that what I'm here for

  9. #9
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chr / Asc converter @ http://tools.intelidev.com/misc/chrasc.asp

    Type in a number, and it will give you the character, or type in a character for the number.
    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  10. #10
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I must be the only freak that prefers to use ""!

    I find it soooo much easier to work with...


  11. #11
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    D, you arn't the only one...just the only one LEFT ALIVE.
    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  12. #12
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,294
    Mentioned
    123 Post(s)
    Tagged
    1 Thread(s)
    Originally posted by KodeKrash
    D, you arn't the only one...just the only one LEFT ALIVE.
    HaHA! Missed me. I use "" all the time.....

    Kode,

    I would love to see the coding standards you've trained your people to work under sometime. i'd bet it would make for some interesting reading....
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  13. #13
    SitePoint Zealot
    Join Date
    Oct 1999
    Location
    France
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My 2 centimes -- write a function to do the replace, this will make your code much tidier and save lots of typing/debugging. Create a function called e.g. SafeSQL that takes a string, then every time you want to replace before saving to the DB you can write

    SafeSQL("don't")

    in your code, and in the function you can do the replace of the ' anyway you like! No-one will know ...
    --
    Veronica Yuill
    Archetype IT

  14. #14
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this maybe:
    Code:
    Public Function CleanQuotes( ByVal strDirty, boolRemove )
    	strData = Replace( Replace( strDirty, Chr(147), Chr(34) ), Chr(148), Chr(34) )
    	strData = Replace( Replace( strData, Chr(146), Chr(39) ), Chr(96), Chr(39) )
    	If Not CBool( boolRemove ) Then
    		strData = Replace( strData, Chr(39), String( 2, Chr(39) ) )
    		strData = Replace( strData, Chr(34), Chr(39) & Chr(34) )
    	ElseIf CBool( boolRemove ) Then
    		strData = Replace( strData, Chr(39), Chr(32) )
    		strData = Replace( strData, Chr(34), Chr(32) )
    		Do While InStr( 1, strData, String( 2, Chr(32) ) ) > 0
    			strData = Replace( strData, String( 2, Chr(32) ), Chr(32) )
    		Loop
    	End If
    	CleanQuotes = Trim( strData )
    End Function
    Sample usage:

    strCleanText = CleanQuotes( "This string has an apostrophe, doesn't it?", False )
    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  15. #15
    SitePoint Wizard big_al's Avatar
    Join Date
    May 2000
    Location
    Victoria, Australia
    Posts
    1,661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Why write a big function when there is already one made for you?

    Server.HtmlEncode
    .NET Code Monkey

  16. #16
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Encoding is not the answer in a highly dynamic setting where HTML is only ONE of about TWENTY possible output methods.

    (Incidentally, you would get fired )
    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  17. #17
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Actually I do too, but it's probably from "learning under" D
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  18. #18
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've had to deal with this heaps. Im the developer of www.techbuy.com.au , and that runs ASP and SQL Server 2000. The best way is to simple create a function, as mentioned above, something like this:

    function ReplaceQuotes(strStuff)
    ReplaceQuotes = Replace(strStuff, "'", "''")
    end function

    This will replace single quotes with doubles. You can add the double quote replacements as well. WIth MS SQL, you must escape a single quote with two single quootes. There doesn't seem to be a lot of documentation on this, and when I started developing about 4 years ago, It stumped me.

    Just remember, when you creat a function, it exists in one spot and can be changed just once, but, if you do little manual changes to your code, you will have a hard time finding which ones you changed in the future if you need to modify them.
    SiteTell.com: Get the best viral marketing tool on the planet and watch as the number of unique visitors to your site soars!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •