Results 1 to 4 of 4

Thread: The equivilant to...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    The equivilant to...

    What is the equivilant to Asc() in .net. I know you can use Asc() but does .Net have a built in way to convert a String character to it's Ascii value?

    Hinder

  2. #2
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Re: The equivilant to...

    VB Code:
    1. Imports System
    2. Imports System.Text
    3. Imports Microsoft.VisualBasic
    4.  
    5. Namespace Convert_Example
    6.     Class MyConvertExampleClass
    7.         Shared Sub Main()
    8.             Dim unicodeString As String = "This string contains the unicode character Pi(" & ChrW(&H03A0) & ")"
    9.  
    10.             ' Create two different encodings.
    11.             Dim ascii As Encoding = Encoding.ASCII
    12.             Dim [unicode] As Encoding = Encoding.Unicode
    13.  
    14.             ' Convert the string into a byte[].
    15.             Dim unicodeBytes As Byte() = [unicode].GetBytes(unicodeString)
    16.  
    17.             ' Perform the conversion from one encoding to the other.
    18.             Dim asciiBytes As Byte() = Encoding.Convert([unicode], ascii, unicodeBytes)
    19.  
    20.             ' Convert the new byte[] into a char[] and then into a string.
    21.             ' This is a slightly different approach to converting to illustrate
    22.             ' the use of GetCharCount/GetChars.
    23.             Dim asciiChars(ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)) As Char
    24.             ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0)
    25.             Dim asciiString As New String(asciiChars)
    26.  
    27.             ' Display the strings created before and after the conversion.
    28.             Console.WriteLine("Original string: {0}", unicodeString)
    29.             Console.WriteLine("Ascii converted string: {0}", asciiString)
    30.         End Sub
    31.     End Class
    32. End Namespace

    http://msdn2.microsoft.com/en-us/lib....encoding.aspx

  3. #3
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Re: The equivilant to...

    http://msdn.microsoft.com/library/de...47c2210998.asp

    Or this?

    And what i understand there, the Asc() function is still around in .Net

  4. #4
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Re: The equivilant to...

    There is no real direct "equivalent" to the Asc function in .NET. It is still around in the Microsoft.Visualbasic namespace, and you can still use it. Strings in .NET are all Unicode characters, so in order to do the same as the Asc() function, you have to use System.Text encoders and decoders, and some was displayed above by figa....

    A good link I found that explains strings pretty well... Dr. GUI
    http://msdn.microsoft.com/library/?u...asp?frame=true

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width