[파일명: 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: 여섯
'프로그래밍 > BASIC' 카테고리의 다른 글
FreeBASIC 언어로 역삼각함수, 역쌍곡선함수 값을 구하는 예제 (0) | 2013.01.02 |
---|---|
클래스 상속(subclassing) 예제 for .NET with Visual Basic (0) | 2009.05.01 |
스트링 배열에서 스트링 찾기(find) with Visual Basic (0) | 2009.04.27 |
스트링 배열 정렬(sorting)하기 with Visual Basic (0) | 2009.04.20 |
손으로 계산하는 긴자리 곱셈표 만들기 with Visual Basic (0) | 2009.03.08 |