If it's not Korean, I want to delete it.

Asked 2 years ago, Updated 2 years ago, 20 views

I read the text file in Java and convert it into Korean

If it is not Korean among the converted contents, I want to delete all of them.

What should I do?

java

2022-09-21 22:14

1 Answers

I don't know what format I'll receive it, but for example, the following form

String [] regex1 = {"aa","a1","11","ㅁ1","ㅁ","ㅁa"};
        for(int i = 0; i < regex1.length; i++) {
        if(!regex1[i].Matches * [I - ㅎㅏ - has drawbacks - hi] + (".*")) 
            System.out.println(regex1[i]);

Results

aa

a1

11

When you do it with a single string...

String regex2 = "1g$@!3nasdfe4d212@@5d22";
String removehangul = "";
for (int i = 0; i < regex2.length(); i++) 
    if (Character.getType(regex2.charAt(i)) == 5) 
        System.out.print(regex2.charAt(i));
    else
        removehangul += regex2.charAt(i);
System.out.println("\n"+removehangul);

Results

ㄴㄷ<

1$@!3asdfe4212@@522


2022-09-21 22:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.