views:

559

answers:

2

I have the following line of code.

<%= Html.Encode(string.Join(", ", item.company1.companies.Select(x => x.company_name).ToArray())) %>

Would it be possible to somehow replace the comma with a line break?

A: 

Have you tried with Environment.NewLine?

<%= Html.Encode(string.Join(Environment.NewLine, item.company1.companies.Select(x => x.company_name).ToArray())) %>

or "\r\n"

<%= Html.Encode(string.Join("\r\n", item.company1.companies.Select(x => x.company_name).ToArray())) %>

EDIT TO ADD

If the companies are separated by space, the try joining the array by a space character

<%= Html.Encode(string.Join(" ", item.company1.companies.Select(x => x.company_name).ToArray())) %>

EDIT TO ADD 2

Join by a html line break

<%= Html.Encode(string.Join("<br/>", item.company1.companies.Select(x => x.company_name).ToArray())) %>
Jhonny D. Cano -Leftware-
That just shows as a space.
RememberME
maybe item.company1.companies is empty
Jhonny D. Cano -Leftware-
No. I see the list of companies. They're just separated by a space.
RememberME
Then join by space, have you tried? or maybe it is a unicode unrecognized character... i'm just speculating in the case the character is not a space
Jhonny D. Cano -Leftware-
When I join by "\r\n" or Environment.NewLine they show as joined by a space. I would like when they are displayed for there to be a line break between each company. If not, I will leave them separated by commas, but I think a line break would be much more user friendly.
RememberME
If you want to "display" them, try joining with a "<br/>" that way, after each company, it willl break
Jhonny D. Cano -Leftware-
that's the quick and dirty... it would be better a list or something like that
Jhonny D. Cano -Leftware-
Putting "<br />" inside the Join displayed the companies with "<br />" between them rather than a line break.
RememberME
A: 

I got it.

<%= Html.Encode(string.Join("***", item.company1.companies.Select(x => x.company_name).ToArray())).Replace("***", "<br />") %>

RememberME