Skip to content

Instantly share code, notes, and snippets.

@sh-cho
Created September 5, 2017 16:51
Show Gist options
  • Save sh-cho/aff7f56c0e48994c3560eb7d69337b06 to your computer and use it in GitHub Desktop.
Save sh-cho/aff7f56c0e48994c3560eb7d69337b06 to your computer and use it in GitHub Desktop.
is contain hangul?
#include <stdio.h>
#include <wchar.h> //wcslen
int is_contain_hangul(const wchar_t *str) {
const size_t len = wcslen(str);
const wchar_t start_ch = L'가';
const wchar_t end_ch = L'힣';
register int i;
for (i = 0; i < len; ++i) {
if (str[i] >= start_ch && str[i] <= end_ch)
return 1;
}
return 0;
}
int main() {
wchar_t *test_str1 = L"가나다라마";
wchar_t *test_str2 = L"abcde";
printf("%d\n", is_contain_hangul(test_str1));
printf("%d\n", is_contain_hangul(test_str2));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment