Java String replaceFirst Example
String class replaceFirst method example
String class replaceFirst method example. This example shows you how to use replaceFirst method. This method Replaces the first substring of this string that matches the given regular expression with the given replacement.
Here is the code:-
/*
* @(#) ReplaceFirst1string.java
*Program Shows Replaces the first substring of this string that matches the given regular expression with the given replacement.
* @Version 01-May-2008
* @author Rose India Team
*/
import java.util.regex.Pattern;
class ReplaceFirst1string
{
public static void main(String[] argv)
{
boolean b;
String s="Welcome=to=Rose=India=.net";
String s2;
String t="fghj";
String regex="!";
// Replaces the first substring of this string that matches the given regular expression with the given replacement.
s2 = s.replaceFirst(regex,t);
System.out.println(s2);
}
} |
null
|