Re: Truncated string (still)

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


Date: Wed, 18 Aug 2004 10:03:36 -0400

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)
    ... > time the browser encounters a second ', it will take that to mean the end ... > use that character in the value. ... Or, if you use ' as the delimiter, you ... I will use the phrase Ray did use in his ...
    (microsoft.public.inetserver.asp.db)
  • Re: Insert a double quote into SQL
    ... 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 ... > It did go to the SQL DB when I add an extra double quote. ...
    (microsoft.public.inetserver.asp.db)
  • Re: urlencode and $_GET
    ... URL delimits an HTML reference to a named anchor, whereas %23 does not, it's treated as part of the query string in the HTTP GET request; ... In the context of a clicked hyperlink, these exact characters are transmitted in the corresponding HTTP GET request string. ... mean it to be a delimiter for an HTML anchor identifier. ...
    (comp.lang.php)
  • 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: HTML text in Merge Field
    ... Actually the field's content is in quotes. ... problem if HTML elements other than are included. ... >> nothing to specify what the merge field delimiter is. ...
    (microsoft.public.word.mailmerge.fields)