[파일명:  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
,


[파일명:  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
,


[파일명:  TestStringFindInList.cs]------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;

namespace MyTestApplication1 {

    class TestStringFindInList {

        public static void Main(String[] args) {
            List<string> words = new List<string>(new String[] { "하나", "둘", "셋", "넷", "다섯", "여섯" });
            int where;

            Console.Write("list: ");
            PrintArray(words);
            where = Find(words, "셋");
            if (where > 0) {
                Console.Write("발견!  ");
                Console.WriteLine("Next word of 셋 in list: " + words[where+1]);
            }

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

            Console.Write("list: ");
            PrintArray(words);
            where = Find(words, "셋");
            if (where > 0) {
                Console.Write("발견!  ");
                Console.WriteLine("Next word of 셋 in list: " + words[where+1]);
            }
        }

        public static int Find(List<string> arr, String s) {
            for (int i = 0; i < arr.Count; i++) {
                if (arr[i].IndexOf(s) >= 0)
                    return i;
            }
            return -1;
        }

        public static void PrintArray(List<string> arr) {
            Console.Write("[");
            for (int i = 0; i < arr.Count - 1; i++) {
                Console.Write("{0}, ", arr[i]);
            }
            if (arr.Count > 0)
                Console.Write("{0}", arr[arr.Count - 1]);
            Console.WriteLine("]");
        }
    }
}
------------------------------------------------


컴파일> csc testStringFindInList.cs

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


Posted by Scripter
,


[파일명:  TestStringFindApp.cs]------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;

namespace MyTestApplication1 {

    class TestStringFindApp {

        public static void Main(String[] args) {
            String[] words = new String[] { "하나", "둘", "셋", "넷", "다섯", "여섯" };
            int where;

            Console.Write("array: ");
            PrintArray(words);
            where = Find(words, "셋");
            if (where >= 0) {
                Console.Write("발견!  ");
                Console.WriteLine("Next word of 셋 in array: " + words[where+1]);
            }

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

            Console.Write("array: ");
            PrintArray(words);
            where = Find(words, "셋");
            if (where >= 0) {
                Console.Write("발견!  ");
                Console.WriteLine("Next word of 셋 in array: " + words[where+1]);
            }
        }

        public static int Find(String[] arr, String s) {
            for (int i = 0; i < arr.Length; i++) {
                if (arr[i].IndexOf(s) >= 0)
                    return i;
            }
            return -1;
        }

        public static void PrintArray(Object[] arr) {
            Console.Write("[");
            for (int i = 0; i < arr.Length - 1; i++) {
                Console.Write("{0}, ", arr[i]);
            }
            if (arr.Length > 0)
                Console.Write("{0}", arr[arr.Length - 1]);
            Console.WriteLine("]");
        }
    }
}
------------------------------------------------


컴파일> csc testStringFindApp.cs

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



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

 

Posted by Scripter
,

Scala 언어로는 리스트 대신 배열로 처리하였다.
 
[파일명:  testStringFindInArray.scala]------------------------------------------------
object TestStringFindInArray {
    def quickSort(arr: Array[String], start: Int, end: Int) {
        var i: Int = start
        var k: Int = end
        var pivot: String = ""

        if (end - start >= 1) {
            pivot = arr(start)
            while (k > i) {
                 while (arr(i) <= pivot && i <= end && k > i) {
                     i += 1
                 }
                 while (arr(k) > pivot && k >= start && k >= i) {
                     k -= 1
                 }
                 if (k > i) {
                     swap(arr, i, k)
                 }
             }
            swap(arr, start, k)

            quickSort(arr, start, k - 1)
            quickSort(arr, k + 1, end)
        }
    }

    def swap(arr: Array[String], x: Int, y: Int) {
        var tmp: String = arr(x)
        arr(x) = arr(y)
        arr(y) = tmp
    }

    def find(arr: Array[String], s: String): Int = {
        var i: Int = 0
        for (i <- 0 to arr.length - 1) {
        if (arr(i).indexOf(s) >= 0) {
     return i
        }
        }
    return -1
    }

    def printArray(arr: Array[String]) {
        print("[")
        for (i <- 0 to arr.length - 2) {
           print(arr(i) + ", ")
        }
        println(arr(arr.length - 1) + "]")
    }

    def main(args: Array[String]) {
        var words: Array[String] = Array[String]( "하나", "둘", "셋", "넷", "다섯", "여섯" )
        var where: Int = 0

        print("array: ")
        printArray(words)

        where = find(words, "셋")
        if (where > 0) {
            print("발견!  ")
            println("Next word of 셋 in array: " + words(where+1))
        }

        quickSort(words, 0, words.length - 1)

        print("array: ")
        printArray(words)

        where = find(words, "셋")
        if (where > 0) {
            print("발견!  ")
            println("Next word of 셋 in array: " + words(where+1))
        }
    }
}
------------------------------------------------


컴파일> scalac -encoding ms949 testStringFindInArray.scala

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


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

Posted by Scripter
,


[파일명:  testStringFindInList.lua]------------------------------------------------
function find(arr, s)
    for i = 1, #arr do
     if string.find(arr[i], s) ~= nil then
      return i
        end
    end
    return -1;
end

function printArray(arr)
    io.write("[")
    for i = 1, #arr - 1 do
        io.write(arr[i] .. ", ")
    end
    if #arr > 0 then
        io.write(arr[#arr])
    end
    io.write("]\n")
end

words = { "하나", "둘", "셋", "넷", "다섯", "여섯" }

io.write("list: ")
printArray(words)
where = find(words, "셋")
if where > 0 then
    io.write("발견!  ")
    print("Next word of 셋 in list: " .. words[where+1])
end

print("Sorting...")
table.sort(words)

io.write("list: ")
printArray(words)
where = find(words, "셋")
if where > 0 then
    io.write("발견!  ")
    print("Next word of 셋 in list: " .. words[where+1])
end
------------------------------------------------


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



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

Posted by Scripter
,


[파일명:  testStringFindInList.rb]------------------------------------------------
def find(arr, s)
    for i in 0..arr.size() do
     if arr[i].index(s) != nil
      return i
        end
    end
    return -1;
end

def printArray(arr)
    print("[")
    for i in 0..arr.size() - 1 do
         print(arr[i] + ", ")
    end
    if arr.size() > 0
        print(arr[arr.size() - 1])
    end
    print("]\n")
end

words = ["하나", "둘", "셋", "넷", "다섯", "여섯"]

print("list: ")
printArray(words)
where = find(words, "셋")
if where > 0
    print("발견!  ")
    print("Next word of 셋 in list: " + words[where+1] + "\n")
end

print("Sorting..." + "\n")
words = words.sort()

print("list: ")
printArray(words)
where = find(words, "셋")
if where > 0
    print("발견!  ")
    print("Next word of 셋 in list: " + words[where+1] + "\n")
end
------------------------------------------------


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



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

Posted by Scripter
,


[파일명:  testStringFindInList.py]------------------------------------------------
# coding=ms949

import sys

def find(arr, s):
    for i in range(0, len(arr)):
     if arr[i].find(s) >= 0:
      return i
    return -1;

def printArray(arr):
    sys.stdout.write("[")
    for i in range(0, len(arr) - 1):
         sys.stdout.write(arr[i] + ", ")
    if len(arr) > 0:
        sys.stdout.write(arr[len(arr) - 1])
    print("]")

words = ["하나", "둘", "셋", "넷", "다섯", "여섯"]

sys.stdout.write("list: ")
printArray(words)
where = find(words, "셋")
if where > 0:
    sys.stdout.write("발견!  ")
    print("Next word of 셋 in list: " + words[where+1])

print("Sorting...")
words.sort()

sys.stdout.write("list: ")
printArray(words)
where = find(words, "셋")
if where > 0:
    sys.stdout.write("발견!  ")
    print("Next word of 셋 in list: " + words[where+1])
------------------------------------------------


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



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

Posted by Scripter
,


[파일명:  testStringFindInList.groovy]------------------------------------------------
def find(ArrayList<String> arr, String s) {
    for (int i = 0; i < arr.size(); i++) {
     if (arr.get(i).indexOf(s) >= 0)
      return i
    }
    return -1;
}

def printArray(ArrayList<String> arr) {
    print("[")
    for (int i = 0; i < arr.size() - 1; i++) {
         print(arr.get(i) + ", ")
    }
    if (arr.size() > 0)
        print(arr.get(arr.size() - 1))
    println("]")
}

ArrayList<String> words = ["하나", "둘", "셋", "넷", "다섯", "여섯"] as ArrayList<String>
int where

print("list: ")
printArray(words)
where = find(words, "셋")
if (where > 0) {
    print("발견!  ")
    println("Next word of 셋 in list: " + words.get(where+1))
}

println("Sorting...")
Collections.sort(words)

print("list: ")
printArray(words)
where = find(words, "셋")
if (where > 0) {
    print("발견!  ")
    println("Next word of 셋 in list: " + words.get(where+1))
}
------------------------------------------------


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


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

Posted by Scripter
,


[파일명:  testStringFindInVector.groovy]------------------------------------------------
def find(Vector<String> arr, String s) {
    for (int i = 0; i < arr.size(); i++) {
     if (arr.elementAt(i).indexOf(s) >= 0)
      return i;
    }
    return -1;
}

def printArray(Vector<String> arr) {
    print("[");
    for (int i = 0; i < arr.size() - 1; i++) {
         print(arr.elementAt(i) + ", ");
    }
    if (arr.size() > 0)
        print(arr.elementAt(arr.size() - 1));
    println("]");
}


String[] data = [ "하나", "둘", "셋", "넷", "다섯", "여섯" ] as String[]
Vector<String> words = new Vector<String>()
for (int i = 0; i < data.length; i++) {
    words.add(data[i])
}
int where

print("vector: ")
printArray(words)
where = find(words, "셋")
if (where > 0) {
    print("발견!  ")
    println("Next word of 셋 in vector: " + words.elementAt(where+1))
}

println("Sorting...")
Collections.sort(words)

print("vector: ")
printArray(words)
where = find(words, "셋")
if (where > 0) {
    print("발견!  ")
    println("Next word of 셋 in vector: " + words.elementAt(where+1))
}
------------------------------------------------


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


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

Posted by Scripter
,