Professional Web Applications Themes

Truncated string (still) - ASP Database

Hi all, On July the fifth I did ask about the same question on this forum. Ray answer me with a with good examples but I miss something and I cannot get the expected result. I will use the phrase Ray did use in his response, which is: Joe's cat walked up to Mary O'Brien's dog and said, "Meow!" The phrase is stored in an Access 2000 table text field exactly as shown above. What I did is: I iterate the records gathering the information in a Tmp variable in order to construct an HTML <TABLE> once at the EOF. ...

  1. #1

    Default Truncated string (still)

    Hi all,

    On July the fifth I did ask about the same question on this forum. Ray
    answer me with a with good examples but I miss something and I cannot
    get the expected result. I will use the phrase Ray did use in his
    response, which is: Joe's cat walked up to Mary O'Brien's dog and said,
    "Meow!"

    The phrase is stored in an Access 2000 table text field exactly as shown
    above.
    What I did is: I iterate the records gathering the information in a Tmp
    variable in order to construct an HTML <TABLE> once at the EOF. Before
    storing de F.Value in the Tmp variable, I format the text using
    an UDF called FormatStr (see at the end of that text)

    sValue = FormatStr(F.Value)
    Response.Write sValue & "<BR>" '*** this output the
    phrase as expected
    Tmp = Tmp & "<TD BGCOLOR=" & sRowColor & "
    valign='Top'>" & _
    "<INPUT TYPE=Text NAME='Comment' SIZE=50 VALUE
    =" & _
    Server.HTMLEncode(sValue) & "></TD>"
    this output only the first word which is Joe's (truncated at the first
    space). Looking at the source in the browser, the phrase is as expected.
    When using <INPUT TYPE=HIDDEN rather than INPUT TYPE=Text the phrase is
    output as expected too! If I remove Server.HTMLEncode I get the same bad
    output. The problem exist only in the "Text" control and the problem is
    caused by the spaces between words. When I removed all spaces, the ' and
    " are managed correctly and the whole phrase is output (whitout
    spaces)..!
    What to do?


    function FormatStr(s)
    dim i
    dim NewStr
    dim loFound
    NewStr = ""
    loFound = False
    if s <> vbNullString then
    if len(s) > 0 then
    for i = 1 to Len(s)
    if InStr(i,chr(34),s) = i then
    loFound = True
    NewStr = NewStr & chr(34) & mid(s,i,1)
    else
    NewStr = NewStr & mid(s,i,1)
    end if
    next
    end if
    end if
    if (NewStr <> "") and (loFound) then
    FormatStr = chr(34) & NewStr & chr(34)
    '*** I tried to replace chr(34) with ' and with "&Quot;" with the
    same result
    else
    FormatStr = NewStr
    end if
    Response.Write FormatStr & "<br>" '*** this output the phrase as
    expected
    ' here is the formated phrase "Joe's cat walked up to Mary O'Brien's
    dog and said, ""Meow!"""
    end function

    I hope my english is clear enough!
    Help will be greatly appreciate
    thank's in advance
    serge




    Serge Guest

  2. #2

    Default Re: Truncated string (still)

    The problem here is simply an HTML problem (but with an ASP solution). Take
    these lines of HTML:

    1. <input type=text value=Mary's cat said "meow.">

    2. <input type='text' value='Mary's cat said "meow."'>

    3. <input type="text" value="Mary's cat said "meow."">


    None of those will display what you want.

    In number 1, there is no ' or " delimiting the value of the input, so you
    will only see text up until the first space.
    ______
    [Mary's]
    ŻŻŻŻŻŻ

    In number 2, ' is the delimiter for the value of the input. So, the first
    time the browser encounters a second ', it will take that to mean the end of
    the value of the input. Anything after that is just unrecognized markup
    that the browser will ignore. So, you would see:
    ____
    [Mary]
    ŻŻŻŻ

    In number 3, ' is the delimiter for the value of the input. This time, the
    first time the browser encounters a " character, it will take that to mean
    the end of the value. So, you'd see:
    ________________
    [Mary's cat said ]
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ


    Basically, if you're going to delimit your form values with ", you cannot
    use that character in the value. Or, if you use ' as the delimiter, you
    cannot use ' in the value. I suggest you pick a delimiter and stick with
    it. If you want to follow the "strict" rules that are being phased into
    HTML, X-HTML, or whatever, you should select the " as your value delimiter.
    So, assuming you pick ", and you religiously always use it to delimit any
    inline values in a tag, your solution is this:


    <%
    '''drop that other function you had.
    Function SafeOut(s)
    SafeOut = Replace(s,"""","&quot;")
    End Function

    sValue = Recordset.Fields.Item(ColumnName).Value

    Tmp = Tmp & "<TD BGCOLOR=""" & sRowColor & """ valign=""Top"">" & _
    "<INPUT TYPE=""Text"" NAME=""Comment"" SIZE=""50"" VALUE=""" & _
    SafeOut(sValue) & """></TD>"
    Response.Write Tmp
    %>



    Ray at work




    "Serge Myrand" <qc.ca> wrote in message
    news:qc.ca... 


    Ray Guest

  3. #3

    Default Re: Truncated string (still)

    I underspoke and mis-spoke a bit here!

    In number 3, " is the delimiter, not '.

    Also, forget about the function I put in there. That won't deal with < or >
    characters, for one thing. Just Server.HTMLEncode your value. Sorry.

    Updated:

    <%
    sValue = Recordset.Fields.Item(ColumnName).Value

    Tmp = Tmp & "<TD BGCOLOR=""" & sRowColor & """ valign=""Top"">" & _
    "<INPUT TYPE=""Text"" NAME=""Comment"" SIZE=""50"" VALUE=""" & _
    Server.HTMLEncode(sValue) & """></TD>"
    Response.Write Tmp
    %>

    Ray at work


    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:phx.gbl... 
    >
    >[/ref]


    Ray Guest

  4. #4

    Default Re: Truncated string (still)

    Hi,

    Now it's ok. Thank you very much for your help. I wonder way the string is
    returned correctly when the control is different from Text control!

    thank's again
    serge

    "Ray at <%=sLocation%> [MVP]" wrote:
     [/ref]

    Serge Guest

Similar Threads

  1. String truncated at the first space in the string
    By Serge Myrand in forum ASP Database
    Replies: 5
    Last Post: July 6th, 10:42 AM
  2. String or binary data would be truncated error
    By Ivan Demkovitch in forum ASP
    Replies: 3
    Last Post: September 18th, 10:39 PM
  3. #24777 [NEW]: $_GET values truncated at %3C in query string
    By csnyder at chxo dot com in forum PHP Development
    Replies: 0
    Last Post: July 23rd, 08:59 PM
  4. error: String or binary data would be truncated.
    By Scott A. Keen in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 11th, 04:40 PM
  5. Replies: 0
    Last Post: July 10th, 03:58 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139