Help with formatting

F

fatima.issawi

Hello,

I am creating a web page using c# and asp.net. I am trying to populate
a list box by reading text from a file.

The text in the file has leading spaces in order to show a hierarchy of
the items. I would like this formatting to show up in the listbox, but
it seems that strings are trimmed before adding them to the listbox.

Is there any way for the spaces in the strings I am adding to a list
box be kept? Is there another way of doing this or another control I
can use? Any help is appreciated.

If you need more clarification, please let me know.

Thanks,
Fatima
 
D

Dave Sexton

Hi Fatima,

In the future you should post questions related to ASP.NET to the
microsoft.public.dotnet.framework.aspnet newsgroup.

ASP.NET isn't removing the spaces, the browser just isn't displaying them.
HTML whitespace is normally collapsed into a single space when rendered in a
browser.

Unfortunately, you can't just simply use the " " sequence to provides
spaces because ASP.NET will automatically encode it so it becomes,
" ", which will be displayed in the list box as text.

Try the following:

string space = HttpUtility.HtmlDecode(" ");

string item = " Four Spaces";

lstTextFromFile.Items.Add(item.Replace(" ", space));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top