There is a question: to completely delete str1 from str2, use C # To implement
I asked if code is used for implementation. The feedback is that my answer is simple:
If (String. IsEmptyOrNull (str1) return; If (String. IsEmptyOrNull (str2) return; Str2 = str2.Replace (str1, String. Empty ); |
The other party asked me if I could give all the strings to replace in this method. I was a small hacker. Because I'm not sure if replace is all or if the first match is met, replace will be returned.
I will answer the question. recursion can be used.
So let me use recursion to do the following:
Public void Replace (ref string str1, ref string str2) {
If (String. IsEmptyOrNull (str1) return; If (String. IsEmptyOrNull (str2) return; If (str2.IndexOf (str1) =-1) return; Else str2 = str2.Replace (str1, String. Empty ); Replace (ref str1, ref str2 ); } |
You can see that this method is feasible.
However, the result is that I tried my first method, which is also possible.
Now I understand that they want to implement the String Replace principle, but the result is wrong. In fact, it is simple. The built-in method or string replace code is not allowed in the question requirements.