Dave's Brain

Browse - Programming Tips - How can I do a simple case insensitive string replace?

Date: 2013aug26
Language: Java

Q.  How can I do a simple case insensitive string replace?

A.  This example will make all cases of "heLLO" into "Hello"

Pattern pat = Pattern.compile("hELLo", Pattern.CASE_INSENSITIVE); String changeHello(String in) { return pat.matcher(in).replaceAll("Hello"); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.