Remove Punctuations from String Java

PROGRAM TO REMOVE PUNCTUATIONS FROM A STRING


public class Test
{
    public static void main(String[] args)
    {
        // input string
        String str = "Welcome???@@##$ to#$% Trans$%^&Geek";
          
        // similar to Matcher.replaceAll
        str = str.replaceAll("\\p{Punct}","");
          
        System.out.println(str);
    }
      
}

OUTPUT
Welcome to TransGeek


Comments

Post a Comment

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java