Removing "." (periods) in IP address using regex

Hi,
Having trouble with the following code.  Not sure why it's not working.  I'm trying to remove the periods (.) from IP addresses, so that I just have a 12 digit number.  For example the IP address of 123.456.789.101 should be converted into 123456879101.  I know the problem is in my regex statement.  If I comment the regex line out, and simply use the  "string ipNumber = ip;" then I get the IP address printed out as expected.  However, if I use the regex line, then the output is blank or null.
public partial class _Default : System.Web.UI.Page
{
    string userIP = HttpContext.Current.Request.UserHostAddress;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        lbAddress.Text = "IP-Address: " + hostAddress + " IP-Number: " + IPAddressConverter(userIP);
 
    }
 
    protected string IPAddressConverter(string ip)
    {
        string ipNumber = Regex.Replace(ip, ".", "");
        //string ipNumber = ip;
        return ipNumber;
    }
}

Open in new window

LVL 10
P1ST0LPETEAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
try \. or [.]
0
 
gdupadhyayConnect With a Mentor Commented:

use:
string ipNumber  = Regex.Replace(ip, "[.]", "");
I will work.
 
0
 
TechTiger007Connect With a Mentor Commented:
why dont you try this

protected string IPAddressConverter(string ip)
    {
        string ipNumber = ip.Replace(".", "");
        //string ipNumber = ip;
        return ipNumber;
    }

0
 
P1ST0LPETEAuthor Commented:
TechTiger007:
That didn't make much sense.  The code you posted, is the code I'm already using and didn't work.
0
 
P1ST0LPETEAuthor Commented:
Thank you ozo and qdupadhyay.
0
All Courses

From novice to tech pro — start learning today.