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

seqarray=TTnnTTTnnTnnnnTTTTTT

seqarray(0)=TT

seqarray(1)=TTT

seqarray(2)=T

seqarray(3)=TTTTTT

Update:

Update 2:

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

Rating
• W.B.G
Lv 6

因為你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): 剛剛測試過的

我的方法可以試試看

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

seqarray = Split(seq, "n" )

Split Function

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