Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to replace Case-Insensitive chars in a String in Java?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 701
    Comment on it

    Sometimes we need to replace some characters with some other set of characters. To replace a Case-Insensitive chars from string you can use the below example:

    package com.demo;
    
    public class TestApps {
    
        /*
          *@param args
         */
        public static void main(String[] args){
    
            String s = "This is to replace Check String check with pattern.";
        String b = s.replaceAll("(?i:check)", "#@!*");
        System.out.println(b);
            }
    }
    

    output:

    This is to replace #@!* String #@!* with pattern.

    in the above example I'm replacing chars "check", it will replace both String "Check" and "check".

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: