How do I make spaces invisible in Console.ReadLine?
I am making a program, and I want the spaces invisible for the iPad to read (for example, I want the same outcome between "A B C", and "ABC"). Please help me figure out how to do this.
string input = Console.ReadLine().Replace(" ",""); This is much cleaner, than the others.
Replace blank spaces with nothing so that blank spaces are removed. Here's how you can do it. str.Replace(' ', ''); // 'str' is your string.
You can use String.Replace. For example: string text = “A B C“; string rep = text.Replace(' ',''); //output ABC
@Andrew In C# the .Replace(); will replace the first argument with the second one, all in the string. Doesn't matter how much, for example, 'Space' are there.
The best answers have: str = str.Replace(' ',''); as solution, but in fact, the second argument ('') is not valid expression, because ' marks enclose a character, and if there is no character between the signs, it cannot be interpreted. You should use: str = str.Replace(" ", ""); as mentioned in other answers. Or in full code: string input = Console.ReadLine().Replace(" ", "");
@Andrew he means in C#. In JS it's string.split(' ').join('');
To solve this, we have to replace the space with nothing using string function str.Replace(" ","");
u can also use strcpy() in cpp
hmm, try a no space method, or a different language
use trim method
@Hammad the String.Trim() method replaces the whitespace characters on the FRONT and on the END of the string, but NOT INSIDE it. Example: " Hello World! ".Trim() returns: "Hello World!"
Why turkısh dont language
I guess that Console.WriteLine (string.Empty) too