首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎样排除每行重复的字符解决方案

2012-02-26 
怎样排除每行重复的字符例如文本框内容:虎,龙,蛇,马,羊,虎,猴,鸡,狗,狗,鼠,牛,兔,龙,蛇,羊,龙,猴,狗,猪,鼠

怎样排除每行重复的字符
例如
文本框内容:
虎,龙,蛇,马,羊,虎,
猴,鸡,狗,狗,鼠,
牛,兔,龙,蛇,羊,龙,
猴,狗,猪,鼠,猪,虎,
龙,蛇,马,羊,鸡,
狗,猪,鼠,虎,蛇,
猴,猴,鸡,狗,
猪,牛,牛,龙,蛇,

改为:
虎,龙,蛇,马,羊,
猴,鸡,狗,鼠,
牛,兔,龙,蛇,羊,
猴,狗,猪,鼠,虎,
龙,蛇,马,羊,鸡,
狗,猪,鼠,虎,蛇,
猴,鸡,狗,
猪,牛,龙,蛇,

意思就是删除每行重复的字符.

谢谢   给个代码

[解决办法]
按行读入内容到str1变量里
dim i as long
dim str2 as string
dim str3 as string

str2= " "
i=len(str1)
do while i> 0
str3=left(str1,1)
str2=str2 & str3
str1=replace(mid(str1,2),str3, " ")
i=len(str1)
loop
MsgBox str2
[解决办法]
一楼的程序稍微修改下就可以了.

strTmp= " "
arrTmp=split(strLine, ", ")

for i=0 to ubound(arrtmp)
if trim(arrTmp(i)) <> " " then
if instr(strTmp,trim(arrTmp(i))) <1 then
strtmp=trim(arrTmp(i))& ", "
end if
end if
next

msgbox strtmp

如果没有分割符,那就用替换法.修改一下一楼的程序就可以了.
[解决办法]
应该有正解了!取出判断就可以了!
[解决办法]
Private Sub Command1_Click()
Dim strText As String
strText = Text1.Text
Dim i As Integer, j As Integer, pos1 As Integer, pos2 As Integer
Dim strTmp() As String, str1 As String
Do
pos2 = InStr(pos1 + 1, strText, vbCrLf, vbTextCompare)
If pos2 = 0 Then pos2 = Len(strText)
strTmp = Split(Mid(strText, pos1 + 1, pos2 - pos1 - 1), ", ")
For j = UBound(strTmp) To LBound(strTmp) Step -1
For i = j - 1 To LBound(strTmp) Step -1
If strTmp(j) = strTmp(i) Then
strTmp(j) = " "
Exit For
End If
Next i
Next j
For i = LBound(strTmp) To UBound(strTmp)
If strTmp(i) <> " " Then str1 = str1 & strTmp(i) & ", "
Next i
str1 = str1 & vbCrLf
If pos2 <> Len(strText) Then pos1 = pos2 Else pos1 = 0
Loop While pos1 > 0
Text1.Text = str1
End Sub

热点排行