Re: Truncated string (still)

From: Ray at <%=sLocation%> [MVP] (%=sLocation%)
Date: 08/18/04


Date: Wed, 18 Aug 2004 10:14:51 -0400

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:OBZYVwShEHA.2764@TK2MSFTNGP11.phx.gbl...
> 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" <info@softdelirium.qc.ca> wrote in message
> news:41234DE4.7966CDBE@softdelirium.qc.ca...
>> 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
>>
>>
>>
>>
>
>



Relevant Pages

  • Re: Truncated string (still)
    ... The problem here is simply an HTML problem. ... ' is the delimiter for the value of the input. ... first time the browser encounters a " character, it will take that to mean ... I will use the phrase Ray did use in his ...
    (microsoft.public.inetserver.asp.db)
  • Re: Insert a double quote into SQL
    ... > first time the browser encounters a " character, it will take that to mean ... > use that character in the value. ... Or, if you use ' as the delimiter, you ... >> It did go to the SQL DB when I add an extra double quote. ...
    (microsoft.public.inetserver.asp.db)
  • Re: OpenSSH: spaces in user name
    ... Unruh> quotes and double quotes into my name. ... such a delimiter plays a very particular ... In your case you want it to either be a character in a name, ... humans but even more confusing to the computer. ...
    (comp.security.ssh)
  • Re: reading csv files
    ... >> stream, so, after the first name is extracted, the subsequent ... delimiter character, and not provide a complete solution to reading a CSV ... The next such call extracts 'yyyy', and ',', and the ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Syntax Problem
    ... If we can identify the specific character that is the delimiter for the ... Can you copy and paste the special delimiter character into a newsgroup post ... >> Oae is the extension requested by the College Board of Examiners in New ... >>> The Database Name argument is the database you are exporting to. ...
    (microsoft.public.access.macros)