I want to replace first occurrence of String in the following.
String test = \"see Comments, this is for some test, help us\"
**If test c
You can use following method.
public static String replaceFirstOccurrenceOfString(String inputString, String stringToReplace,
String stringToReplaceWith) {
int length = stringToReplace.length();
int inputLength = inputString.length();
int startingIndexofTheStringToReplace = inputString.indexOf(stringToReplace);
String finalString = inputString.substring(0, startingIndexofTheStringToReplace) + stringToReplaceWith
+ inputString.substring(startingIndexofTheStringToReplace + length, inputLength);
return finalString;
}
Following link provide examples for replacing first occurrence of string using with and without regular expressions.