+ 8
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.
15 ответов
+ 25
string input = Console.ReadLine().Replace(" ","");
This is much cleaner, than the others.
+ 23
Replace blank spaces with nothing so that blank spaces are removed. Here's how you can do it.
str.Replace(' ', ''); // 'str' is your string.
+ 13
You can use String.Replace.
For example:
string text = “A B C“;
string rep = text.Replace(' ','');
//output
ABC
+ 12
@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.
+ 5
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(" ", "");
+ 2
Thanks, everyone!
+ 2
@Andrew he means in C#.
In JS it's string.split(' ').join('');
+ 2
To solve this, we have to replace the space with nothing using string function str.Replace(" ","");
0
" "
0
u can also use strcpy() in cpp
0
hmm, try a no space method, or a different language
0
use trim method
0
@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!"
0
Why turkısh dont language
- 1
I guess that Console.WriteLine (string.Empty) too