Here is a pretty simplistic usage of a GUID:
<% set typ = CreateObject("Scriptlet.TypeLib") Response.Write typ.guid & "foo" set typ = nothing %> |
Notice that 'foo' is nowhere to be found on the page. For some reason, the GUID string comes with two extra characters, and they get 'swallowed up' by the response.write call. I believe this is a bug in either the Win32 CoCreateGUID API, or how the scriptlet type library implements that call. I have sent in a report to Microsoft about this issue; in the meantime, there are at least two workarounds. One is to manually strip off the offending characters, and the other is to Server.HTMLEncode the string (which essentially does the same thing).
<% set typ = CreateObject("Scriptlet.TypeLib") guidStr = cstr(typ.GUID) ' make it conform to the size of a GUID, 38 chars: Response.Write LEFT(guidStr, 38) & "foo" ' encode the string: Response.Write Server.HTMLEncode(guidStr) & "foo" set typ = nothing %> |
Note that using CSTR and/or assigning the string to a local variable does nothing, on its own, to alleviate the problem. Also, this isn't solely an ASP issue... the behavior occurs in ASP.NET as well.