VBA,TRIM部分路径

编程入门 行业动态 更新时间:2024-10-25 06:31:27
本文介绍了VBA,TRIM部分路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 让我说我有一个路径:stack / overflow / question / help / please。 最终结果是:help / please。有没有人有一个代码,我可以在这里说明我要解析的/数量。

它类似于文本列,但我想保留在一个单元格。

谢谢

解决方案

你可以写一个这样的函数:

函数RightPart(s As String,d As String,n As Long)As String Dim A As Variant Dim i As Long,ub As Long Dim t As String A = Split(s,d) ub = UBound(A)如果n> = ub然后 RightPart = s 退出函数 End If 对于i = ub - n + 1 To ub t = t& A(i)& IIf(i ub,d,)下一个i RightPart = t 结束函数

然后 RightPart(:stack / overflow / question / help / please,/,2)评估为help / please

Lets say I have a path : stack/overflow/question/help/please . And end result is : help/please.

Does anyone have a code where I can state how many "/" I want to parse.

its similar to text to columns but I would like to keep it in one cell.

Thanks

解决方案

You could write a function something like this:

Function RightPart(s As String, d As String, n As Long) As String Dim A As Variant Dim i As Long, ub As Long Dim t As String A = Split(s, d) ub = UBound(A) If n >= ub Then RightPart = s Exit Function End If For i = ub - n + 1 To ub t = t & A(i) & IIf(i < ub, d, "") Next i RightPart = t End Function

Then RightPart(":stack/overflow/question/help/please","/",2) evaluates to "help/please"

更多推荐

VBA,TRIM部分路径

本文发布于:2023-10-31 16:37:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546657.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   VBA   TRIM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!