Sisältö - Muuttujatyypit - Char

Char luokka


Esimerkkejä char luokan käytöstä.

        Dim ch As Char
        Dim st As String
        Dim totuus As Boolean
        Dim i As Integer
        Dim d As Double
        '
        ' onko numero
        ch = "1"c  ' c kirjain kertoo että kyseessä on char
        st = "2341B"
        totuus = Char.IsDigit(ch) 'true
        totuus = Char.IsDigit(st, 2) 'true
        'testi onko kirjain
        totuus = Char.IsLetter(ch) 'fase
        totuus = Char.IsLetter(st, 2) 'false
        'kirjain tai numero
        totuus = Char.IsLetterOrDigit(ch) 'true
        'onko numero
        totuus = Char.IsNumber(ch) 'true
        'onko kontrolli kirjain
        ch = Chr(9) 'tab
        totuus = Char.IsControl(ch)
        'onko pienellä
        ch = Chr(9) 'tab
        totuus = Char.IsLower(ch) 'false
        ch = "1"
        totuus = Char.IsLower(ch) 'false
        ch = "!"
        totuus = Char.IsLower(ch) 'false
        ch = "r"
        totuus = Char.IsLower(ch) 'true
        'onko isolla
        totuus = Char.IsUpper(st, 4) 'true  "B"
        totuus = Char.IsUpper(st.Chars(4)) 'true  "B"
        ' onko piste tai pikkku
        ch = ","c
        totuus = Char.IsPunctuation(ch)
        'onko erotin
        For i = 1 To 2255
            If Char.IsSeparator(ChrW(i)) Then Debug.Write(i, Chr(i)) ' i=32= " " ja 160
        Next
        'mikä tämä on
        For i = 0 To 2255
            If Char.IsSurrogate(ChrW(i)) Then Debug.Write(i, ChrW(i)) '
        Next
        'onko symboli
        For i = 0 To 255
            If Char.IsSymbol(ChrW(i)) Then Debug.Write(ChrW(i), " ") ' : $ : + : < : = : > : ^ : ` : | : ~ : ¢ : £ : ¤ : ¥ : ¦ : § : ¨ : © : ¬ : ® : ¯ : ° : ± : ´ : ¶ : ¸ : × : ÷
        Next
        'onko tyhjä välilyönti
        For i = 0 To 2255
            If Char.IsWhiteSpace(ChrW(i)) Then Debug.Write(i, " ") ' : 9 : 10 : 11 : 12 : 13 : 32 : 133 : 160
        Next
        'vakioita
        ch = Char.MaxValue
        Debug.Write(AscW(ch)) '65535
        ch = Char.MinValue ' nothing
        'muunnoksia
        ch = Char.ToLower("A") '"a"c
        ch = Char.ToUpper(ch) '"A"c
        st = Char.ToString(ch) '"A"
        'muunnos stringistä merkiksi
        ch = Char.Parse(st) '"A"c
        '8 bit funktio
        i = Asc("A"c) '65
        ch = Chr("78") 'N
        '16 bit muunnos
        i = AscW(ChrW(1048)) '1048
        ' muunnos doubleksi
        d = Char.GetNumericValue(ch)
        'unicode ryhmä
        Dim uc As System.Globalization.UnicodeCategory
        uc = Char.GetUnicodeCategory(ch)
        st = uc.ToString 'UppercaseLetter