拆分字符串直到特定的子字符串
Split the string till specific substring
我有一个参考列表。我必须将作者姓名与参考列表中的引文作者进行比较。我必须将字符串拆分到年份,所以我只能得到作者姓名,但我不知道如何进一步进行。
例如,给定以下文本:
Sperrin, M., Jaki, T., & Wit, E. (2010). Probabilistic relabelling strategies for the label switching problem in Bayesian mixture models. Statistics in Computing, 20, 357-366.
我要提取作者姓名:
Dim txt As String
Dim txtarray() As String
txt = "Sperrin, M., Jaki, T., & Wit, E. (2010). Probabilistic relabelling strategies for the label switching problem in Bayesian mixture models. Statistics in Computing, 20, 357-366."
txtarray = Split(txt, ",")
//Split will split the entire text, and I need the text only until the year
预期输出:txtarray = ("Sperrin", " M.", " Jaki", " T."," & Wit")
试试这个:
Sub GetAuthors()
Dim txt As String, authors As String, authorsArray() As String
txt = "Sperrin, M., Jaki, T., & Wit, E. (2010). Probabilistic relabelling strategies for the label switching problem in Bayesian mixture models. Statistics in Computing, 20, 357-366."
authors = VBA.Trim(VBA.Mid$(txt, 1, InStr(1, txt, "(", vbTextCompare) - 1))
authorsArray = VBA.Split(authors, ",")
End Sub
基本上这会搜索第一个 (
以找到日期的开始位置,仅创建作者的子字符串,然后将其拆分为 ,
。
显然,这仅在日期存在且格式为 (YYYY)
时才有效
我有一个参考列表。我必须将作者姓名与参考列表中的引文作者进行比较。我必须将字符串拆分到年份,所以我只能得到作者姓名,但我不知道如何进一步进行。
例如,给定以下文本:
Sperrin, M., Jaki, T., & Wit, E. (2010). Probabilistic relabelling strategies for the label switching problem in Bayesian mixture models. Statistics in Computing, 20, 357-366.
我要提取作者姓名:
Dim txt As String
Dim txtarray() As String
txt = "Sperrin, M., Jaki, T., & Wit, E. (2010). Probabilistic relabelling strategies for the label switching problem in Bayesian mixture models. Statistics in Computing, 20, 357-366."
txtarray = Split(txt, ",")
//Split will split the entire text, and I need the text only until the year
预期输出:txtarray = ("Sperrin", " M.", " Jaki", " T."," & Wit")
试试这个:
Sub GetAuthors()
Dim txt As String, authors As String, authorsArray() As String
txt = "Sperrin, M., Jaki, T., & Wit, E. (2010). Probabilistic relabelling strategies for the label switching problem in Bayesian mixture models. Statistics in Computing, 20, 357-366."
authors = VBA.Trim(VBA.Mid$(txt, 1, InStr(1, txt, "(", vbTextCompare) - 1))
authorsArray = VBA.Split(authors, ",")
End Sub
基本上这会搜索第一个 (
以找到日期的开始位置,仅创建作者的子字符串,然后将其拆分为 ,
。
显然,这仅在日期存在且格式为 (YYYY)