-1

私はこの文字列を持っています

 Dim test As String = "12,32,12,32,12,12,32,15,16,15,14,12,32"

文字列を取得したい

newstr = 12,32,15,16,14

私はこれだけ試しました

Dim test As String = "12,32,12,32,12,12,32,15,16,15,14,12,32"
Dim word As String
Dim uc As String() = test.Split(New Char() {","c})
For Each word In uc
' What can i do here?????????
Next

一意の番号のみ vb asp.net でそれを行うにはどうすればよいですか

正しい答え

Dim test As String = "12,32,12,32,12,12,32,15,16,15,14,12,32"
                Dim word As String
                Dim uc As String() = test.Split(New Char() {","c}).Distinct.ToArray
                Dim sb2 As String = "-1"
                For Each word In uc
                    sb2 = sb2 + "," + word
                Next
                MsgBox(sb2.ToString)
4

4 に答える 4

6
Dim test As String = "12,32,12,32,12,12,32,15,16,15,14,12,32"
Dim uniqueList As String() = test.Split(New Char() {","c}).Distinct().ToArray()
于 2012-11-17T06:10:41.067 に答える
2
    Dim test As String = "12,32,12,32,12,12,32,15,16,15,14,12,32"
    'Split into an array
    Dim testArray As String() = test.Split(",")
    'remove duplicates
    Dim uniqueTestArray As String() = testArray.Distinct().ToArray())
    'Concatenate back to string
    Dim uniqueString As String = String.Join(",", uniqueTestArray)

またはすべて 1 行で:

   Dim uniqueString As String = String.Join(",", test.Split(",").Distinct().ToArray())
于 2012-11-17T06:22:09.340 に答える
0

更新申し訳ありませんが、新しい文字列を一緒に追加するのを忘れました

解決:

Dim test As String = "12,32,12,32,12,12,32,15,16,15,14,12,32"

Dim distinctArray = test.Split(",").Distinct()

Dim newStr As String = String.Join(",", distinctArray.ToArray())

トレーニングリファレンス:このWebサイトで、これらのタイプのプログラミングの課題を簡単にするLINQのガイドを確認してください。LINQチュートリアル

于 2012-11-17T06:07:42.977 に答える