StrConv Function

Convert a string as specified by a conversion type.

warning

This constant, function or object is enabled with the statement Option VBASupport 1 placed before the executable program code in a module.


语法:

StrConv(string As String, Conversion As Integer, [ LCID ])

返回值:

String

参数:

string: Any valid string expression.

Conversion: The type of conversion to perform, as defined in the table below.

Conversion

Value

Description

vbUpperCase

1

Converts Text characters to uppercase.

vbLowerCase

2

Converts Text characters lowercase.

vbProperCase

3

Converts the first letter of every word in Text to uppercase.

vbWide

4

Converts narrow (half-width) characters in Text to wide (full-width) characters.

vbNarrow

8

Converts wide (full-width) characters in Text to narrow (half-width) characters.

vbKatakana

16

Converts Hiragana characters in Text to Katakana characters.

vbHiragana

32

Converts Katakana characters in Text to Hiragana characters.

vbUnicode

64

Converts Text characters to Unicode characters using the default code page of the system.

vbFromUnicode

128

Converts Text characters from Unicode to the default code page of the system.


LCID Optional. The Locale ID in decimal number. If this parameter is omitted, it assumes the system Locale ID. Refer to the file msi-encodinglist.txt for the available LCID values.

示例:


Option VBASupport 1
Option Explicit
Sub Test_StrConv
    Print StrConv("abc EFG hij", vbUpperCase) '= "ABC EFG HIJ"
    Print StrConv("abc EFG hij", vbLowerCase) ' =  "abc efg hij"
    Print StrConv("abc EFG hij", vbProperCase) ' = "Abc Efg Hij"

    REM Converts narrow (single-byte) characters in string to wide
    Print StrConv("ABCDEVB¥ì¥¹¥­¥å©", vbWide) ' = "ABCDEVB¥ì¥¹¥­¥å©"

    REM Converts wide (double-byte) characters in string to narrow (single-byte) characters
    Print StrConv("ABCD@$%23'?EG", vbNarrow) ' = "ABCD@$%23'?EG"

    REM Converts Hiragana characters in string to Katakana characters
    Print StrConv("かたかな", vbKatakana) ' = "カタカナ"

    REM Converts Katakana characters in string to Hiragana characters
    Print StrConv("カタカナ", vbHiragana) '= "かたかな"

    REM  Assumes CP-1252 encoding associated with en-US locale used in unit tests.
    Dim x() As Byte
    x = StrConv("ÉϺ£ÊÐABC", vbFromUnicode)
    Print UBound(x) ' 8 characters
    Print x(2) ' = 186
    Print StrConv(x, vbUnicode)' = "ÉϺ£ÊÐABC"
End Sub

请支持我们!