试一试下述办法(自己调试调试,我没有调试): dim i as integer dim str as stringstr = "100ATcgTAgg 124.." for i =1 to 255 if (i>=vbkeya and i<=vbkeyz) or (i>=vbkeyA and i<=vbkeyZ) then str = replace(str,chr(i),"") end if next i
dim a,a1 as string dim g as integer a="100ATcgTAgg 124..." g = InStr(a, "ATcg") a1=mid(a,g,4) a1就是要取的字符串
Replace 只能替换掉已知的字符,文本中如果有不知道的字符怎么解决?字符串中我只想要A T c g 四个字符,其余的字符未知,而且都不要。Replace 好像不管用的。
dim a,a1 as string dim g as integer a="100ATcgTAgg 124..." g = InStr(a, "ATcg") a1=mid(a,g,4) a1就是要取的字符串
试一试: dim i as integer dim str as stringstr =“100ATcgTAgg 124..." for i = 34 to 255 if i>= vbkeya and i<=vbkeyz then ' elseif i>=vbkeyA and i<=vbkeyZ then ' else str = replace(str,chr(i),"") '之外的全部K掉 end if next i
1. 分段处理,比如每次只取出1万个字符进行处理。
2. 每隔一定的时间(如1000个字符)插入doevents语句,以便让用户可以处理其它的事情或取消循环的运行.
返回字符串,其中指定数目的某子字符串被替换为另一个子字符串。
语法
Replace(expression, find, replacewith[, compare[, count[, start]]])
Replace 函数的语法有以下参数:参数 描述
expression 必选。 字符串表达式 包含要替代的子字符串。
find 必选。被搜索的子字符串。
replacewith 必选。用于替换的子字符串。
start 可选。expression 中开始搜索子字符串的位置。如果省略,默认值为 1。在和count 关联时必须用
count 可选。执行子字符串替换的数目。如果省略,默认值为 -1,表示进行所有可能的替换。在和 start 关联时必须用。
compare 可选。指示在计算子字符串时使用的比较类型的数值。有关数值,请参阅“设置”部分。如果省略,缺省值为 0 ,这意味着必须进行二进制比较。
设置
compare 参数可以有以下值:
常数 值 描述
vbBinaryCompare 0 执行二进制比较。
vbTextCompare 1 执行文本比较。
返回值
Replace 返回以下值:
如果 Replace 返回
expression 为零长度 零长度字符串 ("")。
expression 为 Null 错误。
find 为零长度 expression 的副本。
replacewith 为零长度 expression 的副本,其中删除了所有由 find 参数指定的内容。
start > Len(expression) 零长度字符串。
count 为 0 expression 的副本。
说明
Replace 函数的返回值是经过替换(从由 start 指定的位置开始到 expression 字符串的结尾)后的字符串,而不是原始字符串从开始至结尾的副本。
下面的示例利用 Replace 函数返回字符串: Dim MyStringMyString = Replace("XXpXXPXXp", "p", "Y") '二进制比较从字符串左端开始。返回 "XXYXXPXXY"。
MyString = Replace("XXpXXPXXp", "p", "Y", '文本比较从第三个字符开始。返回 "YXXYXXY"。3,, -1, 1)
--------------------------------------------------------------------------------
用Replace把符合条件数据用""替换掉
dim i as integer
dim str as stringstr = "100ATcgTAgg 124.."
for i =1 to 255
if (i>=vbkeya and i<=vbkeyz) or (i>=vbkeyA and i<=vbkeyZ) then
str = replace(str,chr(i),"")
end if
next i
dim g as integer
a="100ATcgTAgg 124..."
g = InStr(a, "ATcg")
a1=mid(a,g,4)
a1就是要取的字符串
dim g as integer
a="100ATcgTAgg 124..."
g = InStr(a, "ATcg")
a1=mid(a,g,4)
a1就是要取的字符串
dim i as integer
dim str as stringstr =“100ATcgTAgg 124..."
for i = 34 to 255
if i>= vbkeya and i<=vbkeyz then
'
elseif i>=vbkeyA and i<=vbkeyZ then
'
else
str = replace(str,chr(i),"") '之外的全部K掉
end if
next i
通常是这样的一段DNA序列:
1 TTATTAGGTT TTTACCTACC CAGGAAAAGC CAACCAACCT CGATCTCTTG 51 TAGATCTGTT CTCTAAACGA ACTTTAAAAT CTGTGTAGCT GTCGCTCGGC 101 TGCATGCCTA GTGCACCTAC GCAGTATAAA CAATAATAAA TTTTACTGTC 151 GTTGACAAGA AACGAGTAAC TCGTCCCTCT TCTGCAGACT GCTTACGGTT 201 TCGTCCGTGT TGCAGTCGAT CATCAGCATA CCTAGGTTTC GTCCGGGTGT 251 GACCGAAAGG TAAGATGGAG AGCCTTGTTC TTGGTGTCAA CGAGAAAACA
Dim strB As String
Dim intPos As Integer
Dim intLen As Integer
strA = "100ATcgTAgAsklsjfdkhAsjvyuAwerldkscvjAsdhAsfjsA;djfsAhcAwehrAufdsfAjsdjcseiudsAjf;kjAsdfj;AskdjfsAkjg 124..."
intLen = Len(strA)
strB = String(intLen + 2, " ")
intPos = 1
Do While InStr(intPos, strA, "A") > 0
intPos = InStr(intPos, strA, "A")
strB = Left(strB, intPos) & "A" & Mid(strB, intPos + 2)
intPos = intPos + 1
Loop
intPos = 1
Do While InStr(intPos, strA, "T") > 0
intPos = InStr(intPos, strA, "T")
strB = Left(strB, intPos) & "T" & Mid(strB, intPos + 2)
intPos = intPos + 1
Loop
intPos = 1
Do While InStr(intPos, strA, "g") > 0
intPos = InStr(intPos, strA, "g")
strB = Left(strB, intPos) & "g" & Mid(strB, intPos + 2)
intPos = intPos + 1
Loop
intPos = 1
Do While InStr(intPos, strA, "c") > 0
intPos = InStr(intPos, strA, "c")
strB = Left(strB, intPos) & "c" & Mid(strB, intPos + 2)
intPos = intPos + 1
LoopDebug.Print Replace(strB, " ", "") ' HERE IS WHAT YOU WANT!!!End Sub如果要区分大小写,把ATgc分别改成chr(65),chr(84),chr(103),chr(99)