Mombu the Microsoft Forum

Go Back   Mombu the Microsoft Forum > Microsoft > vbscript string encoding ?
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 17th October 17:41
vilius mockûnas
External User
 
Posts: 1
Default vbscript string encoding ?



Hello,

What encoding vbscript uses for string vars ?
Single byte, double byte ?
I'm using vbscript in wsh environment.

thanks
Vilius
  Reply With Quote


 


2 17th October 17:41
richard mueller [mvp]
External User
 
Posts: 1
Default vbscript string encoding ?



The best discussion of variable typing in VBScript is in the Scripting
Guide. For example:

http://www.microsoft.com/technet/scr..._vbs_eves.mspx

Use the Table of Contents at the left in the page to navigate to more
information.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
  Reply With Quote
3 17th October 17:41
richard mueller [mvp]
External User
 
Posts: 1
Default vbscript string encoding ?


Looking again, I mis-read your question. I'm out of town and don't have my
references, but I believe VBScript handles strings one byte per character.
But VBScript can use ADO, where you can specify drivers that support other
encodings.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
  Reply With Quote
4 17th October 17:41
ekkehard.horner
External User
 
Posts: 1
Default vbscript string encoding ?


Vilius Mockûnas schrieb:
[...]

[...]
Internally, strings are represented as 16 bit unicode codepoints.
You can use code like

sOmega = ChrW( &H03C9 )
MsgBox sOmega & "," & UCase( sOmega )

to make sure of this. Depending on the codepage and font used by
your console,

WScript.Echo sOmega & "," & UCase( sOmega )

may look less nice.

cscript <yourfile>.vbs

should work for both cases.

Data/Text file can be used in both formats too. There are (optional)
parameters for functions like OpenTextFile, CreateTextFile, or
OpenAsTextStream.

To process utf-8 data, you'll have to resort to extensions, e.g. the
ADODB.Stream component.
  Reply With Quote
5 17th October 17:41
msnews.microsoft.com
External User
 
Posts: 1
Default vbscript string encoding ?


BSTR is wide character formatted. But note that it start with a length
prefix of 4 bytes, and is not 0 terminated (opposite to ANSI C strings).

Best regards,

Frits de Boer
ActiveXperts Software B.V.
http://www.activexperts.com
  Reply With Quote
6 17th October 17:41
mayayana
External User
 
Posts: 1
Default vbscript string encoding ?


In addition to the other info. already provided,
you should know that there are only objects
and variants in VBS. So what's thought of as
a string is actually a variant of subtype string.

Dim s
s = "word"
MsgBox TypeName(s) & vbCrLf & VarType(s)
' Returns "String" and 8
  Reply With Quote
7 17th October 17:41
paul randall
External User
 
Posts: 1
Default vbscript string encoding ?


It is kind of complex. You can only see the content of those strings by
writing them to the screen with a message box or WScript.Echo statement,
which forces the string to be filtered through the Locale filter; what you
see can seem far different from what you think is in the string. You can
also display the Asc() and AscW() functions for each character. I have not
been able to resolve in my mind what the "True" encoding is within VBScript
strings.

The URL:
http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
titled:
HTML Character Sets
has a gap from &#128 through &#159:

} } --- Right curly brace
~ ~ --- Tilde
---  --- Unused
  &nbsp; Nonbreaking space
! ¡ &iexcl; Inverted exclamation
c ¢ &cent; Cent sign

The character set code points within this gap are now 'undefined', or
seeminly inconsistently defined in the scripting regular expression engine.
Some of these code points have a kind of duality, partially dependent on the
'locale' that CScript/WScript is running under.

Try following short script which kind of demonstrates this duality, in that
the Asc and AscW values for some characters are different, which
further clouds the issue of what encoding really is used for the
characters in the string:

Dim i, sMsg
For i = 128 To 159
sMsg = sMsg & vbCrLf & i & vbTab & Chr(i) & vbTab & _
Asc(Chr(i)) & vbTab & ascW(Chr(i))
Next
MsgBox smsg

In the 1082 locale (Maltese), the Asc and AscW values for all characters is
the same, and the Asc value can be greater than 255; this boggles my mind.

The scripting help file script56.chm talks a little about the use of its
locale functions like SetLocale.

-Paul Randall
  Reply With Quote
Reply


Thread Tools
Display Modes




666