vb如何从一组字符串中取重复的字符啊。如text1=“1233651aa",提取重复字符到text2;text2=”13a“
1个回答
展开全部
Option Base 1
Private Sub Command1_Click()
Dim a$()
Text2 = ""
n = Len(Text1)
ReDim a(n)
For i = 1 To n
a(i) = Mid(Text1, i, 1)
'Print a(i)
Next
For i = 1 To n
For j = i + 1 To n
If a(i) = a(j) Then Text2 = Text2 + a(i)
Next j, i
End Sub
Private Sub Command1_Click()
Dim a$()
Text2 = ""
n = Len(Text1)
ReDim a(n)
For i = 1 To n
a(i) = Mid(Text1, i, 1)
'Print a(i)
Next
For i = 1 To n
For j = i + 1 To n
If a(i) = a(j) Then Text2 = Text2 + a(i)
Next j, i
End Sub
追问
,谢谢。虽然重复的字符倒是提取过来了,可是:如果字符串中的字符重复3次以上,text2显示过来却是重复的3个及以上啊
追答
'疏忽了。呵呵。这样就可以了。朋友。
Option Base 1
Private Sub Command1_Click()
Dim a$(), k$
n = Len(Text1)
ReDim a(n)
For i = 1 To n
a(i) = Mid(Text1, i, 1)
'Print a(i)
Next
For i = 1 To n - 1
For j = i + 1 To n
If a(i) = a(j) Then k = a(i): a(j) = ""
Next j
If Len(Text2) Right(Text2, 1) Then Text2 = Text2 + k
End If
Next i
End Sub
Private Sub Form_Load()
Text1 = "122314567489": Text2 = ""
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询