SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    a problem with space

    hey guys, i got the following form that pulls info from the DB into a text field
    Code ASP:
    response.write "<input type='text' name='name1' value='" & RS("PetName") & "' />"
    The problem is when i put a name with ' in it, then it wont write anything after the ', for example for aa'a then it'll write aa

    so to solve it i removed the ' ' from the Value, it solved it but now if i got a text with spaces in it then it wont write anything after the first word
    i thought something like Replace any space with a &nbsp; to solve it, like with VBnewline, BR, but how to do that?

    thanks for the help

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i thought something like Replace any space with a &nbsp; to solve it, like with VBnewline, BR, but how to do that
    seems like an odd question.

    You are currently using replace for things like <br> and now you don't know how to do to use it for &nbsp;

    --did you try looking up how to use the replace function on google first ?

    google : vbscript ASP replace function

    --did you try to show us your code that isn't working ?

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hey dude, whats ur problem? got something againts people that asking questions or what? i appreciate u trying to help but really, seems like u're so expert in web developing why dont u go on and throw up that "one very simple line" that will bring up the solution and finish it?

    just to answer ur questions, yes i did looked at master google, yes i looked at w3schools for VB functions (even when i do know how to use the replace function)

    Again, got back with nothing, now, after i made u happy, will ya give the solution?

    --did you try to show us your code that isn't working ?
    Code:
    response.write "<input type='text' name='name1' value='" & RS("PetName") & "' />"
    i removed the ' ' from the Value, it solved it but now if i got a text with spaces in it then it wont write anything after the first word
    i thought something like Replace any space with a &nbsp; to solve it
    there's simply nothing more to add.

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you just lazy ?

    did you google "remove space " ?
    did you google "remove apostrophe" ?

    did you even try something simple like :

    replace(RS("PetName", " " , "") ' remove space
    replace (RS("PetName","'", "`") ' replace apostrophe

    show us the word that is not coming through correctly...
    show us the failing result ...

    we can't read your mind....

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    are you just lazy ?
    no
    did you google "remove space " ?
    did you google "remove apostrophe" ?
    no, simply because i got more than enough VB guide links, and they didnt lead me to the solution
    did you even try something simple like :

    replace(RS("PetName", " " , "") ' remove space
    yes, that simply didnt change the fact that nothing gets written after the first word.
    replace (RS("PetName","'", "`") ' replace apostrophe
    now thats the first time i see that kind of apostrophe (`), didn't knew there's a difference between the two and now thats probably going to be the answer to my question, ill check it out and reply.

    show us the word that is not coming through correctly...
    show us the failing result ...
    the failing result is not a code, its simply what i said on this topic in post #1

    we can't read your mind....
    there's no need to

    * Edit: Solved it, Thanks for the help, see? google isnt better than u in explaining after all.

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    And to close this out with my interpretation of the answer ...
    Code:
    response.write "<input type='text' name='name1' value='" & RS("PetName") & "' />"
    Failed with values having an apostrophe because an apostrophe effectively closes the value='' string (value='John O'Shea')

    Code:
    response.write "<input type='text' name='name1' value=" & RS("PetName") & " />"
    Failed with results with spaces because the value part has no container ("") so will automatically only accept a single word. And now here's the proper solution.
    Code:
    response.write "<input type=""text"" name=""name1"" value=""" & RS("PetName") & """ />"
    Putting "" inside a VBScript string tells the code to write a single " character.
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,017
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Yeah, Google isn't going to be your friend unless you know how to form the search query and you won't necessarily know how to form the search query unless you have a little Classic ASP background.

    If I am searching Google I always preface my search with vbscript. If I try ASP, I'll get a lot of .NET results but vbscript gets me ASP Classic results as well as Windows scripting results.

    Anyway, I guess you've got this figured out but it raises a good point... You have to sanitize your strings of various characters before using them. Check the Funky Functions thread and search for functions about strings. There's lots of good stuff in here.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development


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
  •