Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - vbscript string encoding ?

Reply
 
Old 10-11-2009   #1 (permalink)
Vilius Mockûnas


 
 

vbscript string encoding ?

Hello,

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

thanks
Vilius



My System SpecsSystem Spec
Old 10-11-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: vbscript string encoding ?


"Vilius Mockûnas" <v_mockunas@newsgroup> wrote in message
news:%23DuCg3nSKHA.3876@newsgroup
Quote:

> Hello,
>
> What encoding vbscript uses for string vars ?
> Single byte, double byte ?
> I'm using vbscript in wsh environment.
>
> thanks
> Vilius
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
--


My System SpecsSystem Spec
Old 10-11-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: vbscript string encoding ?


"Richard Mueller [MVP]" <rlmueller-nospam@newsgroup> wrote in
message news:uMAyteoSKHA.4408@newsgroup
Quote:

>
> "Vilius Mockûnas" <v_mockunas@newsgroup> wrote in message
> news:%23DuCg3nSKHA.3876@newsgroup
Quote:

>> Hello,
>>
>> What encoding vbscript uses for string vars ?
>> Single byte, double byte ?
>> I'm using vbscript in wsh environment.
>>
>> thanks
>> Vilius
>
> 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
> --
>
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
--


My System SpecsSystem Spec
Old 10-11-2009   #4 (permalink)
ekkehard.horner


 
 

Re: vbscript string encoding ?

Vilius Mockûnas schrieb:
[...]
Quote:

> What encoding vbscript uses for string vars ?
> Single byte, double byte ?
> I'm using vbscript in wsh environment.
[...]
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.

Your source code may be written in utf-16 or your standard regional
setting encoding.

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.



My System SpecsSystem Spec
Old 10-11-2009   #5 (permalink)
msnews.microsoft.com


 
 

Re: 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



"Vilius Mockûnas" <v_mockunas@newsgroup> wrote in message
news:%23DuCg3nSKHA.3876@newsgroup
Quote:

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

My System SpecsSystem Spec
Old 10-11-2009   #6 (permalink)
mayayana


 
 

Re: 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
Quote:

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

My System SpecsSystem Spec
Old 10-11-2009   #7 (permalink)
Paul Randall


 
 

Re: vbscript string encoding ?


"Vilius Mockûnas" <v_mockunas@newsgroup> wrote in message
news:%23DuCg3nSKHA.3876@newsgroup
Quote:

> Hello,
>
> What encoding vbscript uses for string vars ?
> Single byte, double byte ?
> I'm using vbscript in wsh environment.
>
> thanks
> Vilius
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


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Add-Content -Encoding UTF8 and -Encoding Unicode Powershell bugs PowerShell
Moving files from one directory to another based on the file namecontains specified string by using vbscript VB Script
VBScript run generates errors with blank spaces in the string to beexecuted VB Script
How export-csv deals with string versus string[] PowerShell
String PRODUCT_NAME was not found in string table Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46