Remove special character from string using RegularExpression in ASP.Net

nauna
 
on Dec 01, 2019 11:24 PM
Sample_319521.zip
1616 Views

hello,

i have this string 

Nikon-D3400-DSLR-Camera-Body-with-Dual-Lens:-AF-P-DX-NIKKOR-18-55-mm-f/3.5---5.6G-VR-+-AF-P-DX-NIKKOR-70-300-mm-f/4.5---6.3G-ED-VR-(16-GB-SD-Card-+-Camera-Bag)--(Black)

i want to remove all specical character and keep only alphabet small and upper case and numbers and their decimal places

except above 2 conditions i want to remove every thing from string.

please advice

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Dec 02, 2019 05:28 AM

Hi nauna,

Refer below code.

C#

protected void Page_Load(object sender, EventArgs e)
{
    string statement = "Nikon-D3400-DSLR-Camera-Body-with-Dual-Lens:-AF-P-DX-NIKKOR-18-55-mm-f/3.5---5.6G-VR-+-AF-P-DX-NIKKOR-70-300-mm-f/4.5---6.3G-ED-VR-(16-GB-SD-Card-+-Camera-Bag)--(Black)";
    statement = System.Text.RegularExpressions.Regex.Replace(statement, @"[^0-9a-zA-Z.]+", "");
    Response.Write(statement);
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim statement As String = "Nikon-D3400-DSLR-Camera-Body-with-Dual-Lens:-AF-P-DX-NIKKOR-18-55-mm-f/3.5---5.6G-VR-+-AF-P-DX-NIKKOR-70-300-mm-f/4.5---6.3G-ED-VR-(16-GB-SD-Card-+-Camera-Bag)--(Black)"
    statement = System.Text.RegularExpressions.Regex.Replace(statement, "[^0-9a-zA-Z.]+", "")
    Response.Write(statement)
End Sub

Output

NikonD3400DSLRCameraBodywithDualLensAFPDXNIKKOR1855mmf3.55.6GVRAFPDXNIKKOR70300mmf4.56.3GEDVR16GBSDCardCameraBagBlack