bits and bytes of my life experiences
With related to my earlier post which demonstrated how to retrieve only numbers in a string using C#, this is how you can do it using TSQL in SQL Server. This will be also become handy if you want to do this in a backend process (SP, Trigger, etc). This is a UDF which you can reuse in your TSQL codes.
USE [DBNAME]
GO
/****** Object: UserDefinedFunction [dbo].[fn_filternumbers] Script Date: 11/27/2009 17:59:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[fn_filternumbers]
(
@Src nvarchar(255)
)
RETURNS nvarchar(255)
AS
BEGIN
declare @Res nvarchar(255)
declare @i int, @l int, @c char
select @i=1, @l=len(@Src)
SET @Res = ''
while @i<=@l
begin
set @c=upper(substring(@Src,@i,1))
IF @c IN ('0','1','2','3','4','5','6','7','8','9')
SET @Res = @Res + @c
set @i=@i+1
end
return(@res)
END
You can use this function in the following manner;
select telephone, dbo.fn_filternumbers(telephone) from users
This will return telephone numbers by removing white spaces, characters and will only return numbers. (i.e +94 (475) 849 984 would return 94475849984)
Please feel free to drop a comment if you have any question on this.
I wanted to retrieve only the number in a string to clean up some telephone numbers users have entered in a system today. So I came across with this nice Regular Expression it is really simple and most importantly it was the fastest method I could found. Here is the code;
public String returnonlyNumbers(String stringValue)
{
return string.Join(null, System.Text.RegularExpressions.Regex.Split(stringValue, "[^\\d]"));
}
The above code would return only the numbers in any given string. For example if you pass the string “+94 (084) 849748 489748” to this method it would return “94084849748489748”.
Hope someone would find this beneficial.
Time travelling is one of the most fascinating concepts in the world of science fictions. Is time travel possible in the real world? This is a question which most of us would have asked from our selves at least once in our life. Anyway it will be a question without a proper answer for another few decades or more.
At least it has become a reality for the web. Yes you can do travel through time in the web. For a example if you want to go to yahoo.com as it was in 1998, it is really possible with the Way Back Machine. The internet archive a non-profit organization is having the worlds biggest digital library of web archives. Apart from the way back machine they also do provide various other tools to analyze the web archive for researchers, students and general public for free.
So go ahead and play around with the Way Back Machine http://web.archive.org/collections/web/advanced.html