請問一ASP中split()函數用法

seqarray=TTnnTTTnnTnnnnTTTTTT

我想將其切割為

seqarray(0)=TT

seqarray(1)=TTT

seqarray(2)=T

seqarray(3)=TTTTTT

也就是說把"n"去除 並把每個T群集 分別放到陣列中

我記得可以用split()

但我用Split(seqArray, "n") 卻切割不出來

Update:

喔不好意思 打太快 應該是"seq=TTnnTTTnnTnnnnTTTTTT"

重點是如何分割@@"

Update 2:

不好意思 seq是會"隨著使用者輸入而有所變動"

所以可以針對會變動的序列 將"n"去除嗎?

Update 3:

套用你的程式後

seqarray(0)=TT

seqarray(1)=""

seqarray(2)=TTT

seqarray(3)=""

seqarray(4)=T

seqarray(5)=""

seqarray(6)=""

seqarray(7)=""

seqarray(8)=TTTTTT

Update 4:

可以把它變成以下結果麼? 不好意思 一直麻煩您@@"

seqarray(0)=TT

seqarray(1)=TTT

seqarray(2)=T

seqarray(3)=TTTTTT

4 Answers

Rating
  • W.B.G
    Lv 6
    1 decade ago
    Favorite Answer

    因為你seq是seq=TTnnTTTnnTnnnnTTTTTT"

    如果下seqarray=split(seq,"nn")

    得到的結果會變成

    seqarray(0)=TT

    seqarray(1)=TTT

    seqarray(2)=T

    seqarray(3)=""

    seqarray(4)=TTTTTT

    所以你只要改這樣就行了

    seqarray=Split(Replace(seq, "nnnn", "nn"), "nn")

    2008-09-24 08:54:22 補充:

    可以,那就改成,我先寫不存在陣列的方式,第二個寫用陣列的方式

    seqarray=split(seq,"n")

    for i=0 to ubound(seqarray)

    if seqarry(i)<>"" then

    response.write seqarray(i) & " "

    end if

    next

    2008-09-24 08:54:32 補充:

    存在陣列的方式

    seqarray=split(seq,"n")

    dim temp(ubound(seqarray))

    dim j=0

    for i=0 to ubound(seqarray)

    if seqarry(i)<>"" then

    temp(j)=seqarray(i)

    j=j+1

    end if

    next

    2008-09-25 17:33:30 補充:

    有點奇怪,我測試是正常的,然後忘了說,如果要用陣列的方法,要印出temp(j)而不是seqarry(i)的東西

    2008-09-25 17:34:06 補充:

    response.write seqarray(i) & "加上換行,被吃字了"

    Source(s): 剛剛測試過的
  • 1 decade ago

    我的方法可以試試看

    Function mySplit(sSplitData)

    set regEx_mySplit = New RegExp

    regEx_mySplit.Pattern = "n+"

    regEx_mySplit.IgnoreCase = True

    regEx_mySplit.Global = True

    mySplit = split(regEx_mySplit.Replace(sSplitData,"n"),"n")

    End Function

    seq="TTnnTTTnnTnnnnTTTTTT"

    m = mySplit(seq)

    for j = lbound(m) to ubound(m)

    response.write m(j) & "<br>"

    next

    Source(s): 自己
  • Ethan
    Lv 4
    1 decade ago

    seqarray = Split(seq, "n" )

    Split Function

    See Also

    Join Function

    Requirements

    Version 2

    Returns a zero-based, one-dimensional array containing a specified number of substrings.

    Split(expression[, delimiter[, count[, compare]]])

    Arguments

    expression

    Required. String expression containing substrings and delimiters. If expression is a zero-length string, Split returns an empty array, that is, an array with no elements and no data.

    delimiter

    Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.

    count

    Optional. Number of substrings to be returned; -1 indicates that all substrings are returned.

    compare

    Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.

    Source(s): MSDN
  • 提姆
    Lv 5
    1 decade ago

    用同一變數先裝字串後裝陣列?

Still have questions? Get your answers by asking now.