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

Namespace MyTestApplication1

    Public Class TestStringFindApp

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

            Console.Write("array: ")
            PrintArray(words)

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

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

            Console.Write("array: ")
            PrintArray(words)

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

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

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


컴파일> vbc testStringFindApp.bas

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



크리에이티브 커먼즈 라이선스
Creative Commons License

 

Posted by Scripter
,