[파일명:  TestStringFindInList.bas]------------------------------------------------
Imports System
Imports System.Collections
Imports System.Collections.Generic

Namespace MyTestApplication1

    Public Class TestStringFindInList

        ' Java 언어의 main 메소드에 해당하는 Visual Basic의 Main
        Shared Sub Main(ByVal args As String())
            'Dim words As New List(Of String) From { "하나", "둘", "셋", "넷", "다섯", "여섯" }
            Dim words As New List(Of String)
            words.Add("하나")
            words.Add("둘")
            words.Add("셋")
            words.Add("넷")
            words.Add("다섯")
            words.Add("여섯")
            Dim where As Integer

            Console.Write("list: ")
            PrintList(words)

            where = Find(words, "셋")
            If where > 0 Then
                Console.Write("발견!  ")
                Console.WriteLine("Next word of 셋 in list: " & words(where+1))
            End If

            Console.WriteLine("Sorting...")
            words.Sort()

            Console.Write("list: ")
            PrintList(words)

            where = Find(words, "셋")
            If where > 0 Then
                Console.Write("발견!  ")
                Console.WriteLine("Next word of 셋 in list: " & words(where+1))
            End If
        End Sub

        Shared Function Find(arr as List(Of String), s as String ) as Integer
            For i = 0 To arr.Count - 1
                If arr(i).IndexOf(s) >= 0 Then
                    Return i
                End If
            Next
            Return -1
        End Function

        Shared Sub PrintList(arr As List(Of String))
            Dim i As Integer
            Console.Write("[")
            For i = 0 To arr.Count - 2
                Console.Write("{0}, ", arr(i))
            Next i
            If arr.Count > 0 Then
                Console.Write("{0}", arr(arr.Count - 1))
            End If
            Console.WriteLine("]")
        End Sub
    End Class
End Namespace
------------------------------------------------


컴파일> vbc testStringFindInList.bas

실행> TestStringFindInList
list: [하나, 둘, 셋, 넷, 다섯, 여섯]
발견!  Next word of 셋 in list: 넷
Sorting...
list: [넷, 다섯, 둘, 셋, 여섯, 하나]
발견!  Next word of 셋 in list: 여섯


크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by Scripter
,