- 1). Enable access to the "regex" class by adding the following code at the top of your file:
Imports System.Text.RegularExpressions - 2). Open your VB.Net file in an editor such as Microsoft Visual Studio.
- 3). Declare the "input,, "pattern" and "replacement" strings to use in the regular expression function by adding the following code in your function:
Dim input As String = "some 0x3Dhex strings0x2A"
Dim pattern As String = "0[xX][A-Fa-f0-9]+"
Dim replacement As String = ""
The "0[xX][A-Fa-f0-9]+" pattern will match any occurrence in the string where there is a "0x" or "0X" followed by hexadecimal characters from "0-9", "A-F" or "a-f." - 4). Call the "Regex.Replace" function to remove hex characters from your string by adding the following code:
Dim result As String = Regex.Replace(input, pattern, replacement) - 5). Display the resulting string by adding the code:
Console.WriteLine("Result: {0}", result)
The example will display "Result: some hex strings ." - 6). Save your VB.Net file. Compile and execute the program to remove the hex characters from your string.
previous post