正则表达式问题,大伙们帮我瞧瞧!

hmbory 2003-12-30 04:45:55
现有一串字符串,要把重复的字符给去掉,怎么办?
例:字符串为"604134a,604134b,604134c,604134a,604134d,604134e,604134c,604134d,604134e,"
得到的结果为"604134a,604134b,604134c,604134d,604134e"

大侠们帮我写写个表达式!谢了
...全文
52 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2003-12-30
  • 打赏
  • 举报
回复
利用关键词的唯一性:
Private Sub Form_Load()
MsgBox norepeat("604134a,604134b,604134c,604134a,604134d,604134e,604134c,604134d,604134e,")

End Sub

Function norepeat(ByVal x As String) As String
On Error Resume Next
Dim temp, temp2 As New Collection
temp = Split(x, ",")
norepeat = ""
For i = 0 To UBound(temp)
temp2.Add temp(i), temp(i)
norepeat = norepeat & "," & temp2(i)
Next
Set temp = Nothing
If Left(norepeat, 1) = "," Then norepeat = Right(norepeat, Len(norepeat) - 1)
End Function
leolan 2003-12-30
  • 打赏
  • 举报
回复
Private function GetStr(byval strSource as string) as string
Dim l_arrTmp() As String
Dim I As Integer
Dim J As Integer
Dim l_strResult As String

'l_arrTmp = Split ("604134a,604134b,604134c,604134a,604134d,604134e,604134c,604134d,604134e,", ",")
l_arrTmp = Split(strSource,",")
For I = 0 To UBound(l_arrTmp) - 1
For J = I + 1 To UBound(l_arrTmp)
If l_arrTmp(I) = l_arrTmp(J) Then
GoTo NextI
End If
Next J
l_strResult = l_strResult & "," & l_arrTmp(I)
NextI:
Next I
GetStr= Right(l_strResult, Len(l_strResult) - 1)
msgbox GetStr
End Sub

Private Sub Command1_Click()
Call GetStr("604134a,604134b,604134c,604134a,604134d,604134e,604134c,604134d,604134e,")
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧