string manipulation

5 views
Skip to first unread message

raj

unread,
Jan 10, 2008, 4:19:47 PM1/10/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

I have a String which has the value :IP > 182.168.0.1 and IP <
182.168.0.10 and i have one more string with value 182.168.0.6

String sTemp = "IP > 182.168.0.1 and IP < 182.168.0.10";
String sValue = "182.168.0.6";

how can i get range of values from sTemp string,i mean the values
between 182.168.0.1 and 182.168.0.10.

i need to check my sValue is in the range of sTemp .





Any one please help me out,thanks in advance

Cerebrus

unread,
Jan 11, 2008, 2:36:41 AM1/11/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I would suggest simply parsing the IP address part of your string into
an instance of the IPAddress class. Then get the IPAddress to a Long
value using the Address property (Note that the docs say that this
method is obsolete, use GetAddresBytes instead)

Dim myAddress as IPAddress
If IPAddress.TryParse("182.168.0.1", myAddress) = True Then
Dim myLongAddress as Long = myAddress.Address
End If

Get all you addresses this way and then check for range.

Charles A. Lopez

unread,
Jan 11, 2008, 10:48:02 AM1/11/08
to DotNetDe...@googlegroups.com
from another point of view...
 
ip addresses (version 4) are a 32 bit value.
 
Instead of thinking of strings think of numerics.
 


 
On 1/11/08, Cerebrus <zor...@sify.com> wrote:

I would suggest simply parsing the IP address part of your string into
an instance of the IPAddress class. Then get the IPAddress to a Long
value using the Address property (Note that the docs say that this
method is obsolete, use GetAddresBytes instead)

Dim myAddress as IPAddress
If IPAddress.TryParse("182.168.0.1 ", myAddress) = True Then
Dim myLongAddress as Long = myAddress.Address
End If

Get all you addresses this way and then check for range.

On Jan 11, 2:19am, raj < 2rajes...@gmail.com> wrote:
> Hi,
>
> I have a String which has the value :IP > 182.168.0.1 and IP <
> 182.168.0.10 and i have one more string with value 182.168.0.6
>
> String sTemp = "IP > 182.168.0.1 and IP < 182.168.0.10";
> String sValue = " 182.168.0.6";
>
> how can i get range of values from sTemp string,i mean the values
> between 182.168.0.1 and 182.168.0.10.
>
> i need to check my sValue is in the range of sTemp .
>
> Any one please help me out,thanks in advance
--
Charles A. Lopez
charle...@gmail.com

Start your career with Charles A. Lopez TECHNOLOGY - Send your resume to charle...@gmail.com

http://cs.nyu.edu/web/People/alumni.html

1-800-GOOG411 - Google's free 411 service

raj

unread,
Jan 11, 2008, 5:48:13 PM1/11/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,
i am using VB script

<script type="text/vbscript">
dim rule,pos
rule="IP>10.10.1.1 and IP<10.10.1.10"

posgreater=instr(rule,">")
Document.write("posgreater: " &posgreater &"</br>")
posand = instr(ucase(rule),"AND")
Document.write("posand: " &posand &"</br>")
poslesser = instr(ucase(rule),"<")
Document.write("poslesser: " &poslesser &"</br>")
strLeftIP = mid(rule,posgreater,posand)
Document.write("strLeftIP: " +strLeftIP &"</br>")
strRightIP = mid(rule,poslesser,len(rule))
Document.write("strRightIP: " +strRightIP)
</script>


o/p is

posgreater: 3
posand: 14
poslesser: 20
strLeftIP: >10.10.1.1 and
strRightIP: <10.10.1.10


i want my strLeftIP and strRightIP sholud contain only 10.10.1.1 and
10.10.1.10 values,any suggestion from trimming >,and and < from
that.so that i can use if -else condition in searching my ip value in
between strLeftIP and strRightIP.

or any other suggestion to compare my ip from that value.
> > Any one please help me out,thanks in advance- Hide quoted text -
>
> - Show quoted text -

Cerebrus

unread,
Jan 12, 2008, 2:23:37 AM1/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi Charles,

Please re-read my post and you will discover that I have suggested
parsing the string into an IPAddress and then converting it to a Long
(a numeric datatype)

If a person needs to do it manually, he could use the simple
algorithm :

IP Number = ((256^3) * a) + ((256^2) * b) + ((256^1) * c) + ((256^0) *
d)
where the IP Address = a.b.c.d

On Jan 11, 8:48 pm, "Charles A. Lopez" <charlesalo...@gmail.com>
wrote:
> from another point of view...
>
> ip addresses (version 4) are a 32 bit value.
>
> Instead of thinking of strings think of numerics.
>
> On 1/11/08, Cerebrus <zorg...@sify.com> wrote:
>
>
>
>
>
>
>
> > I would suggest simply parsing the IP address part of your string into
> > an instance of the IPAddress class. Then get the IPAddress to a Long
> > value using the Address property (Note that the docs say that this
> > method is obsolete, use GetAddresBytes instead)
>
> > Dim myAddress as IPAddress
> > If IPAddress.TryParse("182.168.0.1", myAddress) = True Then
> > Dim myLongAddress as Long = myAddress.Address
> > End If
>
> > Get all you addresses this way and then check for range.
>
> > On Jan 11, 2:19am, raj <2rajes...@gmail.com> wrote:
> > > Hi,
>
> > > I have a String which has the value :IP > 182.168.0.1 and IP <
> > > 182.168.0.10 and i have one more string with value 182.168.0.6
>
> > > String sTemp = "IP > 182.168.0.1 and IP < 182.168.0.10";
> > > String sValue = "182.168.0.6";
>
> > > how can i get range of values from sTemp string,i mean the values
> > > between 182.168.0.1 and 182.168.0.10.
>
> > > i need to check my sValue is in the range of sTemp .
>
> > > Any one please help me out,thanks in advance
>
> --
> Charles A. Lopez
> charlesalo...@gmail.com
>
> Start your career with Charles A. Lopez TECHNOLOGY - Send your resume to
> charlesalo...@gmail.com
>
> http://cs.nyu.edu/web/People/alumni.html
>
> 1-800-GOOG411 - Google's free 411 service- Hide quoted text -

Cerebrus

unread,
Jan 12, 2008, 2:24:30 AM1/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Then you're asking in the wrong group.

STFW !!

On Jan 12, 3:48 am, raj <2rajes...@gmail.com> wrote:
> Hi,
Reply all
Reply to author
Forward
0 new messages