ITPub博客

首页 > 应用开发 > IT综合 > VBA转换IP地址为可比较12位字符串(去掉小数点)

VBA转换IP地址为可比较12位字符串(去掉小数点)

原创 IT综合 作者:pds911 时间:2008-09-04 11:13:23 0 删除 编辑

[原创]转载请注明出处,-THX-

完成功能样例:zhip("10.12.3.251") ->010012003251

Function zhip(ip As String) As String
Dim pos, StartPos, NumChars As Integer
Dim ip_val, ret_str As String

ip_val = ""
ret_str = ""
StartPos = 1
pos = 0
For i = 1 To 4
pos = InStr(StartPos, ip, ".")
If pos > 0 Then
NumChars = pos - StartPos
If Len(NumChars) = 2 Then
ip_val = "0" & Mid(ip, StartPos, NumChars)
ElseIf Len(NumChars) = 1 Then
ip_val = "00" & Mid(ip, StartPos, NumChars)
Else
ip_val = Mid(ip, StartPos, NumChars)
End If
StartPos = pos + 1
ret_str = ret_str & ip_val
Else
If Len(Mid(ip, StartPos)) = 1 Then
ret_str = ret_str & "00" & Mid(ip, StartPos)
End If
If Len(Mid(ip, StartPos)) = 2 Then
ret_str = ret_str & "0" & Mid(ip, StartPos)
End If
If Len(Mid(ip, StartPos)) = 3 Then
ret_str = ret_str & Mid(ip, StartPos)
End If
End If
Next
zhip = ret_str
End Function

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/81211/viewspace-1010116/,如需转载,请注明出处,否则将追究法律责任。

下一篇: Oracle job备忘
请登录后发表评论 登录
全部评论
  • 博文量
    22
  • 访问量
    652731