Strange ASC Codes

S-Soft 646 Reputation points

Hello all, I'm not familiar with chars and encodings, but need to filter input strings char by char and just allow few chars to pass out


I'm confused with some chars ASC codes, like:

133 which is Horizontal ellipsis … but in some conditions I get 8230 instead of 133

146 which is Right single quotation mark ’ but in some conditions I get 8217 instead of 146

Each char has 2 ASC codes?
How to cover them all in my function?

For LoopNo As Integer = 0 To InputString.Length - 1
Select Case Convert.ToInt32(InputString.Chars(LoopNo))
Case 133, 146, etc...
OutString += InputString.Chars(LoopNo)
Case Else
End Select

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,380 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,605 questions
0 comments No comments
{count} votes

Accepted answer
  1. LesHay 7,126 Reputation points

    I would do something like this. Lots of room for improvements as I don't really know what you are planning on.

    Public Class Form1  
    	Dim teststring As String = "1  2A" & Chr(133) & "BA C" & Chr(146) & "de fA"  
    	Dim wanted() As Integer = {65, 133, 146}  
    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
    		Dim OutString As String = GetChars(teststring)  
    		' hover over the OutString variable above to see what it holds.  
    		' Here it is "A…A’A"  
    	End Sub  
    	Function GetChars(s As String) As String  
    		Dim newstring As String = Nothing  
    		For Each c As Char In s  
    			If wanted.Contains(Asc(c)) Then newstring &= c  
    		Return newstring  
    	End Function  
    End Class  
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Olaf Helper 41,331 Reputation points

    I guess you mean more ASCII code, not ASC(ending)

    but in some conditions I get 8217 instead of 146

    ASCII can represent max. 255 characters = 1 byte in size. Unicode uses 2 bytes = can have value higher then 255, see

    0 comments No comments

  2. LesHay 7,126 Reputation points

    See THIS LINK for some info.

    As for your code. Do you want to add multiple characters to the OutString when it already has that character? e.g. InputString = "ABCDAFGAHIJ" so OutString would contain character 'A' value 3 times. or, if already in OutString would only contain the value for 'A' once?