Link to home
Start Free TrialLog in
Avatar of peterp
peterpFlag for United Kingdom of Great Britain and Northern Ireland

asked on

DHTML Edit control with HTML character references (unicode)

I have a database with strings in (Oracle VARCHAR2), which include HTML character references to Unicode characters (e.g. "Γ" for a capital Gamma). (Note, that means the string contains the ASCII sequence mentioned above, not any Unicode characters.)

I can assign this string to DHTMLEditControl1.DocumentHTML, and it displays correctly in the edit control.

The problem is, I want the user to edit the text (not necessarily the Greek bit), so later on I assign the DocumentHTML property back to the string in order to save it to the database again. At that point, the non-ASCII characters are replaced with ?, even though the control has helpfully prepended a META statement indicating that the charset is unicode.

I get the same thing if I use DocumentSave & write it to a file.

Any suggestions? Is there a flag I can set, or another property I can examine? Should I switch to handling the whole string as Unicode? If so, I'd like some pointers about that, because my VB help seems rather ambivalent about the subject!

Using Visual Basic/Studio 6, I can try inspect the DocumentHTML property, and the characters appear to already be ?s before the assignment. I'm not sure how the edit control manages to display them correctly?
Avatar of AzraSound
AzraSound
Flag of United States of America image

You may try using the StrConv function, e.g.,

'editing...
strHTML = StrConv(DHTMLEditControl1.DocumentHTML, vbUnicode)
Avatar of peterp

ASKER

Thanks for that, AzraSound. I can now get "real Unicode" in my strings (i.e not HTML character references).

My problem then moves on: how to display these Unicode strings? Neither a text box nor the DHTML edit control display them correctly. This is presumably because VB "helpfully" converts the strings to ASCCI before passing them to the DLL. (This is inspite of the fact that both VB & WinNT use Unicode for their internal strings). Is there any way I can turn this conversion off - for the project, for a target DLL, or even just for a particular call?

(Note: my last paragraph in the question is a red herring; the characters appear as ?s because the watch & immediate windows in Visual Studio are subject to the same conversions)
Well, if the text box or DHTML edit control want Ascii, go ahead and give it to them.  You can use the StrConv function to go to and from Ascii and Unicode using the vbUnicode and vbFromUnicode constants in the function call.
Avatar of peterp

ASKER

Tried that - the problem is that vbFromUnicode function works as I mentioned above. Alternate bytes are simply stripped off, leaving a mixture of some bytes which are displayed as ASCII characters, with others as question marks.

What I want is to display the actual characters. Unicode is supposed to be the native character set of NT, and is an acceptable character set & encoding for SGML & therefore HTML documents. So, I assumed it would be straight forward to use it.

So, thanks, but I really don't want to convert my string from Unicode to ASCII. If I directly call Windows API functions, I can go for the "wide" character ones. I was just hoping there was a way to use the Unicode with the controls, otherwise I may as well drop this experiment in VB & return to a language which gives me closer control (& requires me to increase my effort estimates!)
Avatar of peterp

ASKER

For anyone interested, I have worked around this by storing HTML Character References in an ASCII character set, instead of real Unicode.

The VB internal strings are Unicode, even though you don't normally see them as such. The following fragment translates a string S$ to another string Out$ which contains ASCII & HTML Character Refs:

Out$ = ""
For i% = 1 To Len(S$)
  c$ = Mid$(S$, i%, 1)
  u% = AscW(c$)
  If (u% <= 255) Then
    out$ = out$ & c$
  Else ' these are the two bytes ones, to be encoded
    out$ = out$ & "&#" & CStr(u%) & ";"
  End If
Next i%

I'm sure experts could write it better, but it works. Out$ can be displayed properly in the DHTMLEdit control.

Peter
Avatar of DanRollins
peterp@devx, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial