Left function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am attempting to collect the user's IP address from a Web App. I then need
to verify the address is not an 'internal' user. I need to compare the left 3
characters of the IP address with a constant. I know I have done this with
the left function in VB. I can't seem to locate a similar function in C#. Can
someone assist?

if (Session["UserIP"].ToString() == "22.")
 
You can do in different ways:
you can :
1. Use string.Substring; to get the idex of first dot you can use
string.IndexOf

2. You can split the string on dots - string.Split('.') and get an array of
IP parts.

3. You can use string.StartsWith("22.") if the "22." is the only option.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top