C
C#2y ago
Ronnie

Can someone explain what the code does step by step?

I don't understand, what does the .replace do and (" ", string.Empty)? And what seems to be the purpose of it?
5 Replies
MODiX
MODiX2y ago
Method: System.String.Replace(Char, Char) Returns a new string in which all occurrences of a specified Unicode character in this instance are replaced with another specified Unicode character. Method: System.String.Replace(String, String) Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string. Method: System.String.Replace(String, String, Boolean, CultureInfo) Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string, using the provided culture and case sensitivity. 3/6 results shown ~ Click Here for more results
React with ❌ to remove this embed.
MODiX
MODiX2y ago
thinker227#5176
REPL Result: Success
string str = "hello world!";
string replaced = str.Replace("l", "L");
Console.WriteLine(replaced);
string str = "hello world!";
string replaced = str.Replace("l", "L");
Console.WriteLine(replaced);
Console Output
heLLo worLd!
heLLo worLd!
Compile: 649.401ms | Execution: 85.147ms | React with ❌ to remove this embed.
Thinker
Thinker2y ago
It essentially just does a search-and-replace on the string it's called on. The first argument is the string to search for, the second argument is the string to replace matches with. This code just replaces all spaces in the string with an empty string, i.e. just removing all spaces.
Ronnie
RonnieOP2y ago
oh ok thanks, how do i call on the second method and is there a specific meaning to "orig"? public CompactString(CompactString orig) { this.saveString = orig.saveString; }
Kouhai
Kouhai2y ago
orig is just the parameter name That method is a constructor It's called by new
Want results from more Discord servers?
Add your server