『壹』 ASP如何過濾數組內重復內容
dim a(4)
a(0)=1
a(1)=1
a(2)=2
a(3)=2
a(4)=3
for n=0 to ubound(a)-1
for s=1 to ubound(a)
if a(s)=a(n) then
a(n)=""
end if
next
next
a_new=filter(a,"")『把a數組裡面是空值的全部刪掉,然後重新組合成一個a_new數組。
for n=0 to ubound(a_new)』列印出a_new數組。
response.write a_new(n)&"<br>"
next
說明:a_new是新生成的數組,去掉了a數組裡面被清空的那些,重新生成了一個開頭角標是0的a_new數組。
『貳』 去掉字元串中間的所有空格的asp代碼怎麼寫
<%
dim mystr,myarray
mystr="Once upon a time,there were three bears."
myarray=SPLIT(mystr)'把字元串分割為數組,默認情況下以空格為分割符
myarray=FILTER(myarray,"t")
'函數FILTER()過濾掉所有不匹配字元串」t」的數組元素。
response.write JOIN(myarray)&"<br>"'把過濾後的字元串連接起來
%>
如果你想從一個句子中過濾掉包含字母t的每一個詞,那麼就在函數Filter()中加入參數false。如下所示:
<%
dim mystr,myarray
mystr="Once upon a time,there were three bears."
myarray=SPLIT(mystr)'把字元串分割為數組,默認情況下以空格為分割符
myarray=FILTER(myarray,"t",false)'函數FILTER()過濾掉匹配特定字元串"t"的所有數組元素
response.write JOIN(myarray)'把過濾後的字元串連接起來
%>
把T改為你想要的空格