Dear Frnds,
I am having a field which contains string(characters) and numeric value
example:-"aamir12000".
i just want to get the number not any text from it without using Substring().
please help in my query.
Thanks & Regards,
Aamir
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 15, 2011, 3:50 AM
Try this...
ALTER FUNCTION dbo.udf_GetNumeric
(@strAlphaNumeric VARCHAR(256))
RETURNS VARCHAR(256)
AS
BEGIN
DECLARE @intAlpha INT
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric)
BEGIN
WHILE @intAlpha > 0
BEGIN
SET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' )
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric )
END
END
RETURN ISNULL(@strAlphaNumeric,0)
END
SELECT dbo.udf_GetNumeric('aamir12000') AS Expr1
thanks
Satyapriya NayakPosted Dec 15, 2011, 3:12 AM
Try this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string s1 = "aamir12000";
string value = Regex.Replace(s1, @"[\D]", "");
MessageBox.Show(value);
}
}
}
Thanks
If this post helps you mark it as answer