StrConv Function [VBA]

Conteníu

# Función StrConv

Convert a string as specified by a conversion type.

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

### Syntax:

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

### Return value:

String

### Parameters:

string: Any valid string expression.

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

Conversion | Valor | Descripción
--- | --- | ---
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.

### Example:

    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) ' = "ＡＢＣＤＥＶＢ￥ì￥¹￥￥å©"

        REM Converts wide (double-byte) characters in string to narrow (single-byte) characters
        Print StrConv("ＡＢＣＤ＠＄％２３＇？ＥＧ", 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 caráuteres
        Print x(2) ' = 186
        Print StrConv(x, vbUnicode)' = "ÉÏº£ÊÐABC"
    End Sub

Temes rellacionaos

Exclusive VBA Functions and Statements