TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET Val, Asc and AscW Functions

Use the Val, Asc and AscW built-in Functions to convert characters to other types.
Val, Asc. Val, Asc and AscW convert characters. From the Char, we get either its integer representation or its numeric representation. Using these Functions, we convert characters into the appropriate integer value.
Example. We use these functions with two characters. The character "a" has a Val of 0 and an Asc of 97. In ASCII, the letter "a" is represented with the number 97. The Val function returned zero because "a" is not a number itself.
VB.NET program that uses Val, Asc, AscW Module Module1 Sub Main() ' Use Val and AscW on char. Dim c As Char = "a"c Dim i As Integer = Val(c) Dim a As Integer = Asc(c) Console.WriteLine(c) Console.WriteLine(i) Console.WriteLine(a) ' Another character. Dim c2 As Char = "2"c Dim i2 As Integer = Val(c2) Dim a2 As Integer = AscW(c2) ' AscW is similar to Asc Console.WriteLine(c2) Console.WriteLine(i2) Console.WriteLine(a2) End Sub End Module Output a 0 97 2 2 50
The second Char in this example contains the digit "2". Val here returns 2. This is the digit contained in the character. The AscW function here returns 50. This is the ASCII numeric representation for the character "2".

Note: The Val, Asc and AscW functions are only available in the VB.NET language, not the C# language.

Summary. In this example, we saw how the Val, Asc and AscW Functions are useful in different situations. If you want to convert a Char to its underlying integer representation, the Asc and AscW functions are ideal.

Tip: If you want to get the number from the Char and turn it into an Integer, the Val function is best.

© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf