[파일명:  TestStringFindApp.cpp]------------------------------------------------
// Filename: TestStringFindApp.cpp
//
// Compile: cl /clr TestStringFindApp.cpp
// Execute: TestStringFindApp

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;

void PrintArray(array<String^>^ arr);

bool Contains(String^ s)
{
    return s->IndexOf("셋") >= 0;
}

int main(array<String^> ^args) {
    array<String^>^ words = gcnew array<String^> { "하나", "둘", "셋", "넷", "다섯", "여섯" };
    int where;

    Console::Write("array: ");
    PrintArray(words);
    where = Array::FindIndex(words, gcnew Predicate<String^>(Contains));
    if (where >= 0) {
        Console::Write("발견!  ");
        Console::WriteLine("Next word of 셋 in array: {0}", words[where+1]);
    }

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

    Console::Write("array: ");
    PrintArray(words);
    where = Array::FindIndex(words, gcnew Predicate<String^>(Contains));
    if (where >= 0) {
        Console::Write("발견!  ");
        Console::WriteLine("Next word of 셋 in array: {0}", words[where+1]);
    }

    return 0;
}
  
void PrintArray(array<String^>^ 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("]");
}
------------------------------------------------


컴파일> cl /clr testStringFindApp.cpp

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


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

 

Posted by Scripter
,