Wednesday, March 28, 2012

How to remove non-Numeric or non-alphameric characters from a string in Sql Server 2005

Hi to all,

I am having a string like (234) 522-4342.

i have to remove the non numeric characters from the above string.

Please help me in this regards.

Thanks in advance.

M.ArulMani

Hi,

How about this:

Public Function StripAlpha(ByVal PassedStr)As String' ' Leaves only any numeric values in passed string 'Dim iAs Integer Dim GotCharAs Boolean Dim HoldStrAs String =""Dim HoldCharAs String =""'Clears Leading / trailing spaces PassedStr = Trim(PassedStr)' Cycle through the string to remove unwanted charactersFor i = 1To Len(PassedStr) HoldChar = Mid$(PassedStr, i, 1)If Not IsNumeric(HoldChar)Then GotChar =True Else GotChar =False End If If Not GotCharThen HoldStr = HoldStr & HoldCharEnd If Next i StripAlpha = HoldStrEnd Function

You just pass in something like StripAlpha("xyz()12345") and it should return just the numbers.

Hope this helps.

Paul

|||

Duplicate post. Please use the other thread if anyone would like to contribute:http://forums.asp.net/t/1111146.aspx

No comments:

Post a Comment