-3

How can I get rid of whitespaces when I don't need them?

I have to check checboxes then add them to a listbox then pass them to a textbox(multiline). Then of course I have to put at the end Listbox1.Items.Add(Environment.NewLine);

This make the items on the textbox separated. But I want that whitespace to be gone when I'm going to process the data. How to remove it?

Christian Vibora
  • 103
  • 1
  • 11
  • 4
    It's not very clear what you are trying to do. I suggest you provide the code you have at the moment, plus the output that you get now, and the output that you actually want. – Brendan Green Jan 27 '16 at 03:12
  • 1
    @Ian for most people [C# string replace does not work](http://stackoverflow.com/questions/13277667/c-sharp-string-replace-does-not-work) :) – Alexei Levenkov Jan 27 '16 at 03:13
  • @AlexeiLevenkov ouch... :s – Ian Jan 27 '16 at 03:13

1 Answers1

1

Your answer is a bit unclear but try a replace such as:

var x = "this is a   test";
x = x.Replace(" ", "");

If that doesn't work I would suggest you look into RegEx.Replace and see if that meets your needs.

If your adding the whitespace yourself at the beginning or end of the string then look at the string.Trim(), string.TrimStart() and string.TrimEnd() methods.

Kelly
  • 6,992
  • 12
  • 59
  • 76