[Solved] Replace Exact String in Java


You can use:

String result = "http://sdsadasd/time/time.jsp?tp=&a".replaceFirst("time\\.jsp", "java.jsp");

Or using the good friend ApacheCommon StringUtils…

String result = StringUtils.replaceOnce("http://sdsadasd/time/time.jsp?tp=&a", "time.jsp", "java.jsp");

For example, you can do:

public static void main(String[] args) {
    String result = "http://sdsadasd/time/time.jsp?tp=&a".replaceFirst("time\\.jsp", "java.jsp");
    System.out.println(result);
}

// Print: 
http://sdsadasd/time/java.jsp?tp=&a 

4

solved Replace Exact String in Java