Results 1 to 23 of 23

Thread: String question

  1. #1

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413

    String question

    I have a problem... how do you pull a " out of a string??? cuz you cant just put""" cuz it just thinks you put too many "... anyone have an idea on what i can do?

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    you can use "'s in strings

    try this:
    VB Code:
    1. Private Sub Form_Load()
    2.     MsgBox """"
    3. End Sub

    what probs you got?

    can you show us the line of code that your stuck with?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Not sure what exactly your trying to do but you could use it's Ascii value. " = 34 *I think*


    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  4. #4

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413
    ok what i'm doing here is a web page that allows users to type what ever they want... now it they type a " in the middle... sql thinks that is the end of the string and disreguards everthing else after that... what i want to do is scan the string for " and replace them with ## and when it is displayed again on a differnt screen change the ## back to " do you understand now??? this is being written to an access database... and the field type is memo.....

  5. #5
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    myString = Join(Split(myString, """"),"##")

    To reassemble when reading

    myString = Join(Split(myString, "##"),"""")
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  6. #6

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413
    that wont work... i need it to pull out all " not "" your code will only work for double " .... andit dosent allow you to do """ it bombs out thinking you errored it..

  7. #7

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413
    here is my error


    Microsoft VBScript compilation error '800a03ee'

    Expected ')'

    /testweb/BulletinBoard/BulletinBoardposting.ASP, line 38

    Descriptions = Replace(Descriptions, """, "##")
    -------------------------------------------^

  8. #8
    RobIII
    Guest
    VB Code:
    1. 'Replace " with *
    2. strTest = Replace(strTest,""""."*")
    3.  
    4. 'or replace it a " with "":
    5. strTest = Replace(strTest,""""."""""")
    6.  
    7. 'or replace it with '' (two single quotes):
    8. strText = Replace(strTest,""""."''")
    etc...etc...

  9. #9

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413
    you dont seem to undstand.... you all are useing 4 """" where what i need is 3 """ and the system does not like this at all...

  10. #10
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    No, YOU don't understand.

    have you even tried the code you were given?

    The occurance of two quotes WITHIN a quoted string collapses to one quote.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  11. #11

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413
    Microsoft VBScript compilation error '800a03f2'

    Expected identifier

    /testweb/BulletinBoard/BulletinBoardposting.ASP, line 38

    Descriptions = Replace(Descriptions,""""."*")
    -----------------------------------------^

    and your code does nothing either 4" does not colapes to 3" have you tried your own examples to see if they work in script????? none of these exampls work... either they error out like up top or i lose all the text after the first "

  12. #12
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Frankly, your ineptitude never ceases to amaze me.

    A) You never indicated until just now that you were programming in ASP. This does make a difference.

    B) You have no clue what you are talking about.

    You will need to do it the long way.

    While Instr(theString, """") > 0
    theString = Left(theString, InStr(theString, """") - 1) & "##" & Mid(theString, inStr(theString, """") + 1)
    Wend

    Now, I don't have an ASP page on-hand, but this is close if not exact, where theString is the string yoy have the quotes in.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  13. #13
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    378

    easy does it....

    use this VB script function (I've used it countless times). It will make any type of data SQL safe.

    VB Code:
    1. '-------------------------------------------------------------------------------
    2. '<*|
    3. ' function SSquote
    4. '   SQL Server database prep function
    5. '
    6. '   This routine makes a string SQL safe.  It should be used RELIGIOUSLY
    7. '   whenever SQL Strings are put together in ASP code.  If you do not use
    8. '   this function (or something like it) in your SQL statements you are probably
    9. '   causing a MAJOR security hole by appending user input directly onto
    10. '   a SQL Statement which is passed into the database server's
    11. '   parsing engine.  Additionally if you don't use this routine database portability
    12. '   and/or database upgrades can be VERY difficult.
    13. '
    14. '   Usage Example:
    15. '
    16. '   SQL = "INSERT INTO tblUsUser (UsID, UsWebCookie, UsDateCreated, UsBrowser, UsWantsEmail) VALUES ("
    17. '   SQL = SQL & quote(UsID, SSNUM)& ", "
    18. '   SQL = SQL & quote(UsWebCookie, SSSTR)& ", "
    19. '   SQL = SQL & quote("", SSDATENOW)& ", "
    20. '   SQL = SQL & quote(request("HTTP_USER_AGENT"),SSSTR)& ", "
    21. '   SQL = SQL & quote(request("EmailOK"), SSBOOL) & ")"
    22. ' Parameters:
    23. '   *string[string]
    24. '       value to be prepped
    25. '   *int_flag[integer]
    26. '       SSSTR = 0
    27. '           This denotes a String or Character variable.  It handles escaping single
    28. '           quotes and deals with NULLs correctly.  The string which is passed
    29. '           is returned enclosed in single quotes, so don't include them in the
    30. '           SQL statement.
    31. '       SSNUM = 1
    32. '           This denotes a Numeric variable (int, long, float, money, percent, etc...)
    33. '           Dollar signs an commas are removed.  If the string passed is not
    34. '           numeric then a NULL is returned for insertion.
    35. '       SSDATE = 2
    36. '           This denotes a Date value for use in an INSERT or WHERE clause.
    37. '           Note that there is no differentiation between INSERT and WHERE dates
    38. '       SSBOOL = 4
    39. '           This denotes a Boolean variable.  "true", "yes" or "1" (case insensitive)
    40. '           are all returned as TRUE for the particular database.  All other values
    41. '           are returned as FALSE.
    42. '       SSDATENOW = 5
    43. '           This flag is slightly different from the above in that it is used to
    44. '           default a date field to the date from the clock of the database server.
    45. '           It is important to use this flag and not the VB Script now() function
    46. '           where accurate timing is required.  When this flag is used the string
    47. '           parameter can be used to specify the offset (in days) from the current
    48. '           system date of the database.
    49. '       SSLIKE = 6
    50. '           For LIKE in a query
    51. '           Surrounds string with '% <string> %'  
    52. 'Output:
    53. '   *[string]
    54. '       outputs the DB prepped string
    55. '/|*>
    56. '-------------------------------------------------------------------------------
    57. function SSQuote(byval string, int_flag)
    58.     if (string <> "") then
    59.         string = replace(string, chr(39), chr(39)&chr(39))   'change apostrophes to double apostrophes
    60.         string = replace(string, chr(34), chr(34)&chr(34)) 'escape double quotes
    61.         string = replace(string, "|", "")   'strip out pipes
    62.  
    63.         Select Case int_flag
    64.         Case SSSTR
    65.             ' String variable handling
    66.             SSQuote = "'" & trim(string) & "'"
    67.         Case SSNUM
    68.             ' Do some string cleaning for numeric fields
    69.             string = replace(string, ",", "")
    70.             string = replace(string, "$", "")
    71.             if (NOT IsNumeric(string)) then
    72.                 SSQuote = "NULL"
    73.             else
    74.                 SSQuote = string
    75.             end if         
    76.         Case SSDATE
    77.             ' SQL Server Date syntax
    78.             SSQuote = "'" & trim(string) & "'"
    79.         Case SSBOOL
    80.             ' Boolean variable handling
    81.             if (lcase(string) = "true" or lcase(string) = "yes" or string = "1") then
    82.                 SSQuote = 1
    83.             else
    84.                 SSQuote = 0
    85.             end if         
    86.         Case SSDATENOW
    87.             ' SQL Server System Date
    88.             SSQuote = "DATEADD(day, " & string & ", GETDATE()) "
    89.         Case SSLIKE
    90.             ' String variable handling
    91.             SSQuote = "'%" & trim(string) & "%'"
    92.         End Select
    93.     else
    94.         ' Handle the case where string is empty
    95.         Select Case int_flag
    96.         Case SSDATENOW
    97.             ' SQL Server System Date
    98.             SSQuote = "GETDATE() "
    99.         Case SSBOOL
    100.             SSQuote = 0
    101.         Case SSSTR
    102.             SSQuote = "''"
    103.         Case SSNUM
    104.             SSQuote = "NULL"
    105.         Case SSDATE
    106.             SSQuote = "NULL"                               
    107.         Case SSLIKE
    108.             SSQuote = "'%%'"               
    109.         End Select
    110.     end if
    111. end function

  14. #14

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413
    Rat you sure are arrogantly dense

    >>>Frankly, your ineptitude never ceases to amaze me.

    >>>>A) You never indicated until just now that you were >>>>programming in ASP. This does make a difference.
    Look up i showed you the error was an asp page....

    >>>>B) You have no clue what you are talking about.
    So i have no clue what i'm talking about when i take your code paste it in and change the var name to the one i'm using and it dosent work... i show the the freggan error and you have the nerve to tell me this?????? then if your code is so great why did you have to change it??



    >>>Now, I don't have an ASP page on-hand, but this is close if >>>not exact, where theString is the string yoy have the quotes in.

    and if your such a genius why cant you just whip up an asp page... or a vb script

  15. #15
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Originally posted by Filter300
    Rat you sure are arrogantly dense
    And if you had any sense at all, we would not have reached this point in the conversation

    So i have no clue what i'm talking about when i take your code paste it in and change the var name to the one i'm using and it dosent work... i show the the freggan error and you have the nerve to tell me this?????? then if your code is so great why did you have to change it??
    Becuase I wrote it for VB for Apps since you never indicated you were using ASP.

    and if your such a genius why cant you just whip up an asp page... or a vb script
    Fine

    I did and it worked exactly as I wrote in the above post.
    See attached.
    Attached Files Attached Files
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  16. #16
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Filter300.....You sure are complaining alot to think that your asking for someone elses help, who is obviously trying to help you.

    You should remember it is YOU that has presented YOUR problem not everyone else, these people are only trying to help you.

    If you don't like their answers or suggestions try investigating it yourself or buy a book.

    It's free information, and beggers can't be choosey

    I'm sorry I imposed, but it's frustrating to sit back and see people trying to help someone and even if it is not successful not even appreciating the effort.

    I spoke out because SO MANY people have helped me SO MANY times in this forum and I appreciate every one of them, even the ones that were not successful - at least they tried.

    Once again I'm sorry if I imposed...

    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  17. #17

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413
    rat if you would have read my original post you can see that i'm asking for a way to remove " not "" your asp page

    <%@Language = "VBScript"%>
    <%
    Dim theString
    theString = "Descretion is the better part of ""valor""."

    response.Write(theString & "<br>")

    While Instr(theString, """") > 0
    theString = Left(theString, InStr(theString, """") - 1) & "##" & Mid(theString, inStr(theString, """") + 1)
    Wend

    response.Write(theString)
    %>

    only works for "" thats not what i asked about at all...


    and joltremari, if you would read the posts quote rat here"Frankly, your ineptitude never ceases to amaze me. " was completely uncalled for... what i asked for from the start was to remove " not "" and you 2 dont seem to understand that.
    i didnt say anything bad twards him till he had to cop an attitude

  18. #18
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Did you even run the page?

    You will see that the output only contains one " not two.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  19. #19
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    378
    Filter300, why not try the funtion I provided, it works!

  20. #20

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413
    ok... i got it working now... thanks for the help

  21. #21
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Can't we all just get along *holds up a nice peace sign*

  22. #22
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Originally posted by Filter300
    rat if you would have read my original post you can see that i'm asking for a way to remove " not "" your asp page
    And apparently, YOU didn't read HIS post:

    Originally posted by Lord_Rat
    The occurance of two quotes WITHIN a quoted string collapses to one quote.
    <removed by admin>

  23. #23

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413

Posting Permissions

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



Click Here to Expand Forum to Full Width