gpt4 book ai didi

excel - 如何在特殊字符后获取部分字符串?

转载 作者:行者123 更新时间:2023-12-01 09:40:53 24 4
gpt4 key购买 nike

我有一个列,我在其中选择递增的编号值,它们的格式是 xx_yy所以第一个是 1_0,第二个是 1_1 等等,不,我们在 23_31

我想获得字符串的右侧,而我已经正确获得了左侧。使用

newActionId = Left(lastActionID, (Application.WorksheetFunction.Find("_", lastActionID, 1) - 1))

我想做下面的事情,下面写人

nextSubid = entire stringvalue AFTER special character "_"

我试过从左到右切换,效果不佳,您有什么建议吗?

最佳答案

您可以使用 Split function获取相关文本。

Syntax: Split(expression, [ delimiter, [ limit, [ compare ]]])

Option Explicit

Sub Sample()
Dim id As String
Dim beforeSplChr As String
Dim afterSplChr As String

id = "23_31"

beforeSplChr = Split(id, "_")(0)
afterSplChr = Split(id, "_")(1)

Debug.Print beforeSplChr
Debug.Print afterSplChr
End Sub

另一种方式

Debug.Print Left(id, (InStrRev(id, "_", -1) - 1)) '<~~ Left Part
Debug.Print Right(id, (InStrRev(id, "_", -1) - 1)) '<~~ Right Part

关于excel - 如何在特殊字符后获取部分字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60485064/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com