我正在处理大量的网址,我需要删除网址的后缀。我使用了LEFT功能但它只能删除.org,.net,.com或任何其他3个字母的后缀。我的问题是,也有网站有2个字母后缀:
http://www.howtouseseo.com/health/resources - > howtouseseo
http://www.hpa.nhs.uk/Topics/InfectiousDiseases/InfectiousDiseasesLinks/ - > HPA
http://hpani.org/Links/smokingcessation.htm - > hpani
http://www.hpcbd.com/Resources.html - > hpcbd
http://hpp.lipscomb.edu/healthcenter/Health-Resources - > hpp.lipscomb
http://www.hpsdma.nic.in/UsefulLinks.html - > hpsdma
这可能吗?
谢谢!
答案 0 :(得分:2)
如果只对网址的第二部分感兴趣,请在模块中编写一个函数并在表格中使用
Public Function StripURL(oRng As Range) As String
StripURL = Split(oRng.Value, ".")(1)
End Function
<强>更新强>
Public Function StripURL(oRng As Range) As String
Dim sURL As String
sURL = oRng.Value
' 1. Keep text after "//"
If InStr(1, sURL, "//", vbTextCompare) > 0 Then sURL = Split(sURL, "//")(1)
' 2. Keep text before first "/"
sURL = Split(sURL, "/")(0)
' 3. Check if contains "www."
If InStr(1, sURL, "www.", vbTextCompare) > 0 Then
' 3a. Remove "www."
sURL = Replace(sURL, "www.", "")
' 4. Check number of dots
Select Case UBound(Split(sURL, "."))
Case 0 To 2
sURL = Split(sURL, ".")(0)
Case Is > 2
sURL = Split(sURL, ".")(0) & "." & Split(sURL, ".")(1)
End Select
Else
' 3b. Check number of dots
Select Case UBound(Split(sURL, "."))
Case 0 To 1
sURL = Split(sURL, ".")(0)
Case Is > 1
sURL = Split(sURL, ".")(0) & "." & Split(sURL, ".")(1)
End Select
End If
StripURL = sURL
End Function
答案 1 :(得分:0)
如果您的输入与您的示例一样简单,您可以尝试:
=MID(MID(A1,12,LEN(A1)-11),1,SEARCH(".",MID(A1,12,LEN(A1)-11))-1)
假设您的数据安排如下:
但是,如果你之间有额外的点,那么这将不会100%起作用 希望这有点让你感到高兴。