List data

Now in my program in C # that mimics lan-messenger, I need to show people who are currently online with one remote hostname on each line. However, the problem is that for this I am using the function

//edited this line out, can't find a .Append for listBox or .AppendLine
//listBox.Append(String );

listBox.Items.Add(new ListItem(String));

      

This displays carriage returns and newline characters (i.e. ... \ r and \ n) as small rectangular rectangles at the end of the hostname. How can I get rid of this?

0


a source to share


4 answers


You can use:

listBox.Append(String.Replace("\r\n", ""));

      



to get rid of these characters

+2


a source


Another option is to consider creating an extension method for the custom finish you are trying to achieve.

/// <summary>
/// Summary description for Helper
/// </summary>
public static class Helper
{
    /// <summary>
    /// Extension Method For Returning Custom Trim
    /// No Carriage Return or New Lines Allowed
    /// </summary>
    /// <param name="str">Current String Object</param>
    /// <returns></returns>
    public static string CustomTrim(this String str)
    {
        return str.Replace("\r\n", "");
    }
}

      



Your line of code looks like this:

listBox.Items.Add(new ListItem(myString.CustomTrim());

      

+1


a source


You can use the Trim string method to remove unwanted characters from the beginning and end of a string. Either call it with no parameters to remove all spaces (including such breaks), or pass in a character array with the characters you want to remove.

0


a source


It looks like you are using some kind of TextBox in one line mode. If so, activate TextBox.Multiline .

0


a source







All Articles