This function cleans a string by removing unwanted characters based on the number of characters passed as a parameter. It uses a regular expression with a pattern that varies depending on the number of characters, either removing all non-numeric characters, all non-alphabetic characters, or all non-alphanumeric characters from the input string. It then returns the cleaned string or converts it to a long if only numeric characters were removed.
This function cleans a string by removing unwanted characters based on the number of characters passed as a parameter. It uses a regular expression with a pattern that varies depending on the number of characters, either removing all non-numeric characters, all non-alphabetic characters, or all non-alphanumeric characters from the input string. It then returns the cleaned string or converts it to a long if only numeric characters were removed.
This function cleans a string by removing unwanted characters based on the number of characters passed as a parameter. It uses a regular expression with a pattern that varies depending on the number of characters, either removing all non-numeric characters, all non-alphabetic characters, or all non-alphanumeric characters from the input string. It then returns the cleaned string or converts it to a long if only numeric characters were removed.
Function Limpia(cadena As String, Optional num_car_az As Byte = 1)
Dim pat As String Select Case num_car_az Case 2: pat = "[0-9]" Case 3: pat = "[^a-z|ñ]" Case Else: pat = "[^0-9]" End Select With CreateObject("vbscript.regexp") .Global = True .IgnoreCase = True .Pattern = pat Limpia = .Replace(cadena, "") End With If num_car_az = 1 Then Limpia = CLng(Limpia) end if End Function