zoukankan      html  css  js  c++  java
  • 分割字符串

    You want to explode a delineated string (e.g. abc; cde; gef; xyz; abc).
    Optionally, also get the unique values with no holes in the list...

    An all LotusScript explode option is just using split:
    linetext = "abc; cde; gef; xyz; abc"
    rowVals = Split(linetxt, ";")


    @Explode & @Trim Only:
    Function LSExplode(strIn As String, sepstr As String) As Variant
    ' this function takes an incoming string (strIn) and turns it into an array separating via sepstr
    ' strIn - incoming string to be converted, e.g. abc;gef;abb;ddd
    Dim evalstr As String ' the string combined for evaluate statement
    Dim evalRtn As Variant ' the returned results of Evaluate
    ' check sepstr
    If sepstr = "" Then
    sepstr =";"
    End If
    ' test strIn
    If strIn="" Then
    LSExplode = ""
    Exit Function
    Else
    ' lets do explode
    evalstr = |@Trim(@Explode("| + strIn + |"; "| + sepstr + |"))|
    evalRtn = Evaluate(evalstr)
    End If
    LSExplode = evalRtn
    End Function

    @Explode & @Unique:
    Function LSExplode(strIn As String, sepstr As String) As Variant
    ' this function takes an incoming string (strIn) and turns it into an array separating via sepstr
    ' strIn - incoming string to be converted, e.g. abc;gef;abb;ddd
    Dim evalstr As String ' the string combined for evaluate statement
    Dim evalRtn As Variant ' the returned results of Evaluate
    ' check sepstr
    If sepstr = "" Then
    sepstr =";"
    End If
    ' test strIn
    If strIn="" Then
    LSExplode = ""
    Exit Function
    Else
    ' lets do explode
    evalstr = |@Trim(@Unique(@Explode("| + strIn + |"; "| + sepstr + |")))|
    evalRtn = Evaluate(evalstr)
    End If
    LSExplode = evalRtn
    End Function

    @Explode & @Unique & @Implode:
    Function LSUnique(strIn As String, sepstr As String) As String
    ' this function takes an incoming string (strIn) and turns it into an array separating via sepstr
    ' this function with @unique also returns only the unique elements of the array
    ' strIn - incoming string to be converted, e.g. abc;gef;abb;ddd
    Dim evalstr As String ' the string combined for evaluate statement
    Dim evalRtn As Variant ' the returned results of Evaluate
    ' check sepstr
    If sepstr = "" Then
    sepstr =";"
    End If
    ' test strIn
    If strIn="" Then
    LSUnique = ""
    Exit Function
    Else
    ' lets do explode
    evalstr = |@Implode(@Trim(@Unique(@Explode("| + strIn + |"; "| + sepstr + |"))); "<br>")|
    evalRtn = Evaluate(evalstr)
    End If
    LSUnique = evalRtn(0)
    End Function

    Function Explode (Byval WordList As String, Sep As String) As Variant

    Dim SepLen As Integer
    Dim WordLocation As Integer
    Dim WordLen As Integer
    Dim SubWordLen As Integer
    Dim InstanceCount As Integer
    Dim TempWordList As String
    Dim endofstring As Integer
    SepLen = Len(Sep)

    WordList = Trim(WordList)
    endofstring = Len(WordList)
    test = Right(WordList, 1)
    If (Right(WordList, 1) = ";") Then
    TempWordList = Left( WordList, endofstring - 1 )
    Else
    TempWordList = WordList
    End If

    InstanceCount = 0

    WordLocation = Instr(TempWordList, Sep)
    While WordLocation > 0
    WordLen = Len(TempWordList)
    SubWordLen = (WordLocation-1)+SepLen
    TempWordList = Right(TempWordList, WordLen - SubWordLen)
    WordLocation = Instr(TempWordList, Sep)
    InstanceCount = InstanceCount+1
    Wend

    Redim ReturnList(InstanceCount)

    WordLocation = Instr(WordList, Sep)
    For i = 0 To InstanceCount
    If WordLocation = 0 Then
    Word = WordList
    ReturnList(i) = Word
    Exit For
    Else
    Word = Left(WordList, (WordLocation - 1))
    End If
    ReturnList(i) = Word
    WordLen = Len(WordList)
    SubWordLen = (WordLocation-1)+SepLen
    WordList = Right(WordList, WordLen - SubWordLen)
    WordLocation = Instr(WordList, Sep)
    Next i

    Explode = ReturnList

    End Function

  • 相关阅读:
    fastjson转换包含date类型属性的对象时报错com.alibaba.fastjson.JSONException: For input string: "13:02:19"
    HTTP Status 500
    org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported
    myeclipse 报错:Set project compiler compliance settings to '1.5'
    Myeclipse安装svn插件
    junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题
    使用mybatis时,sql查出来的结果映射不进逆向工程生成的该模型
    整合mybatis时报错:Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
    TinkerPop中的遍历:图的遍历步骤(3/3)
    TinkerPop中的遍历:图的遍历步骤(2/3)
  • 原文地址:https://www.cnblogs.com/hannover/p/2249705.html
Copyright © 2011-2022 走看看