Enter two strings S1 and S2. Delete All substrings S2. that is, The result string cannot contain S2.
Input Format:
The input two non-empty strings of no more than 80 characters ending with a carriage return are provided in the two lines, corresponding to S1 and S2.
Output Format:
Output The result string after deleting all the substrings S2 in string S1 in one row.
Input example:
Tomcat is a male ccatatcat
Output example:Tom is a male
Import java. util. utility; public class main {public static void main (string [] ARGs)
{CIN = new partition (system. in); string STR = cin. nextline (); string STRC = cin. nextline (); string temp = STR; string result = Str. replaceall (STRC, ""); While (! Result. Equals (temp ))
{
/* If temp and result are not equal, replace them all the time */temp = result; Result = temp. replaceall (STRC, "");} system. out. println (result );}}
Difference between replace and replaceall
Some of them are easy to mix up, so I will detail them here.
The replace parameters are char and charsequence, which can be used to replace characters or replace strings (charsequence is the meaning of string sequences, that is, strings );
The replaceall parameter is RegEx, that is, the replacement based on the Rule expression. For example, you can replaceall ("\ D", "*") to replace all the numeric characters of a string with asterisks;
Similarities: replace all characters with specified characters or strings;
Difference: replaceall supports regular expressions, so the parameter will be parsed (both parameters are), such as replaceall ("\ D", "*"), while replace does not, replace ("\ D", "*") is a string that replaces "\ D" and is not parsed as a regular expression.
There is another difference: "\" is an escape character in Java, so two must be used to represent one. For example, system. Out. println ("\"); only one "\" is printed "\". However, "\" is also an escape character in a regular expression and must be represented by two characters. Therefore, \\\\ is converted to \\\, \\ by a regular expression, so replaceall is replaced with "\" "\\", replaceall ("\\\\", "\\\\\\\\") is required, while Replace ("\\", "\\\\").
If you only want to replace the string that appears for the first time, you can use replacefirst (). This method is also based on the Rule expression, but unlike replaceall (), it only replaces the string that appears for the first time.
String-02. Delete the substring from the string