Hi i need a word VBA script that will clean any non alpha-numeric characters from a…
- User
Hi i need a word VBA script that will clean any non alpha-numeric characters from a string, like the regex [a-zA-Z1-0]. Can you help?
Assistant
Certainly! Below is a VBA function that you can use in Microsoft Word to clean a string by removing any non-alphanumeric characters. This function mimics the behavior of the regex
[a-zA-Z0-9].Function CleanAlphanumeric(ByVal inputString As String) As String Dim i As Integer Dim result As String ' Loop through each character in the input string For i = 1 To Len(inputString) Dim char As String char = Mid(inputString, i, 1) ' Check if the character is alphanumeric If char Like "[A-Za-z0-9]" Then result = result & char End If Next i CleanAlphanumeric = result End Function
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.