www.allfree-stuff.com


Friday, June 25, 2010

Remove duplicate characters in a string in VB


A simple code to remove duplicate characters in a string. Is there any better solution?

Public Function DuplicateTrim(ByVal Value As String) As String

Dim ASCII As Integer
Dim Temp As String

For ASCII = 33 To 126
' Get first location of the letter
If InStr(1, Value, Chr(ASCII), CompareMethod.Binary) > 0 Then
' letter exists
Temp &= Chr(ASCII)
' Remove all characters matching in original
Value = Value.Replace(Chr(ASCII), "")
End If
Next

Return Temp

End Function

22 comments:

葉婷 said...

知識可以傳授,智慧卻不行。每個人必須成為他自己。.................................................................

江婷 said...

幸福不是一切,人還有責任。.................................................................

凱文凱文 said...

所有的資產,在不被諒解時,都成了負債............................................................

張怡 said...

如果成為一支火柴,也要點亮一個短暫的宇宙;如果是一隻烏鴉,也要叫疼閉塞的耳膜。.................................................................

云依恩HFH謝鄭JTR安 said...

nice to know you, and glad to find such a good artical!..................................................................

原秋原秋 said...

文章是心情的反應~~祝妳天天寫的都是讓人開心的好文章哦!!............................................................

李冠文 said...

下次再來希望可以看到新的作品喔。............................................................

姿柯瑩柯dgdd憶曾g智曾 said...

要用心經營哦~~祝福你~~
............................................................

陳佑發 said...

每日都有新日光,每日都有新希望。..................................................

士凱士凱 said...

Subtlety is better than force. ............................................................

吳婷婷 said...

Learning makes life sweet.

凱v胡倫 said...

絕不要羞於承認自己不知道的事。..................................................

家唐銘 said...

A liar is not believed when he speaks the truth.............................................................

郭周志豪欣怡 said...

人生是故事的創造與遺忘。............................................................

小米 said...

我是天山,等待一輪明月。......................................................................

文瓊王王慧山 said...

廢話不多,祝你順心~^^..................................................................

怡靜怡靜怡靜怡雯 said...

所有的資產,在不被諒解時,都成了負債..................................................................

佳張張張張燕張張張張張 said...

讚啦~~多謝分享!!>ˍ<..................................................................

佳張張張張燕張張張張張 said...

nice job! waiting for your new artical.............................................................

佳陳容 said...

時間就是塑造生命的材料。

蒲亮奇 said...

人生有如洶湧的波濤,如果沒有岩石的阻擋,怎能激起美麗的浪花?.. ... ............................................................

lala said...

Thanks for your post and welcome to check: here
.