Click here to watch in Youtube :
https://www.youtube.com/watch?v=kzyy1NC5JtY&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java String [replaceFirst(String regex, String replacement) method] |
/* * public String replaceFirst(String regex, String * replacement) * * Parameters: * ---------- * regex - the regular expression to which this * string is to be matched. * * replacement - the string to be substituted * for the first match. * * Returns: * ------- * Replaces the first substring of this string that * matches the given regular expression with the * given replacement. * * Throws: * ------ * PatternSyntaxException - if the regular * expression's syntax is invalid. */ public class ReplaceFirstDemo { public static void main(String[] args) { String str = "My name is Peter,her name is Juli"; System.out.println("str = " + str); String replacedStr = str.replaceFirst("is", "was"); System.out.println("replacedStr = " + replacedStr); } }
str = My name is Peter,her name is Juli replacedStr = My name was Peter,her name is Juli
https://sites.google.com/site/javaee4321/java/StringDemo_ReplaceFirst_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_ReplaceFirst_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/627e98cff1455d9113a0f59150e05649fae86225/BasicJava/StringDemo_ReplaceFirst_App/?at=master
See also:
No comments:
Post a Comment