Ankita
Ankita

Reputation: 31

To display spaces between text of multiline textbox in label

Prefered output -

Hi
Hello
U            There...

Current output -

Hi Hello U there...

Using replace method with <br/> tags works only for new line. However I need to retain the space between U and There.

Can anyone provide a solution to this?

Upvotes: 3

Views: 1240

Answers (4)

CRC Pro
CRC Pro

Reputation: 19

protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        string sos = "";
        if (TextBox1.Text == sos)
        {
            TextBox1.Text = "00";
        }
        char opo = TextBox1.Text[0];
        char opo1 = TextBox1.Text[1];
        Label1.Text = (opo + " " + opo1);

    }

input to texbox text = 23 autput to Label = 2 3

Upvotes: 0

Pranay Rana
Pranay Rana

Reputation: 176956

Adding to @Jon Skeet answer replace space by &nbsp using regular expression.

string s1 = "He saw   a cute\tdog.";
Regex r = new Regex(@"\s+");
string s3 = r.Replace(s1, "&nbsp;");

Upvotes: 1

K6t
K6t

Reputation: 1845

In html just add null eg:

<html>
<body>

<select>
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
<optgroup >// get a space between 
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1503489

Have you tried using &nbsp; for each space?

Upvotes: 1

Related Questions