请教一个vb 字符串操作的问题

来源:百度知道 编辑:UC知道 时间:2024/07/04 11:41:08
怎么把含有数字字母的字符串里面的英文字母提取出来 组成个字符串?比如我在 text1中输入了 yn123121,现在要返回 yn, 求助高手

dim a as string,s as string
s=""
for i= 1 to len(text1.text)
a=mid(text1.text,i,1)
if asc(a)>=65 and asc(a) <=90 or asc(a)>=97 and asc(a)<=122 then s=s+a
next i

dim r as string,i as integer
r="yn123121"
for i=0 to 9
r=replace(r,trim(str(i)),"")
next i
print r

dim a as string,i as integer
a="yn123121"
for i=0 to 9
a=replace(a,i,"")
next i

a就是你要的结果"yn"了。

for i=1 to len(text1.text)
x=mid(text1.text,i,1)
if x>="a" and x<="z" or x>="A" and x<="Z" then
s=s & x
end if
next
print s

在工程中添加两个文本框和一个按钮控件,复制下面的代码即可
Private Sub Command1_Click()
dim x as string
dim s as string
dim i as integer
s=""
for i= 1 to len(text1.text)
x=mid(text1.text,i,1)
if (asc(x)>=65 and asc(x) <