format a variable value in View -- MVC

pratikshahse
pratikshahse used Ask the Experts™
on
In my view I am getting an address value from my model.

Address is coming up as

adressline 1 | adress line 2 | City | State | zip

I wont this to be formatted in such a way that it shows up as

addressline 1
addressline2
City, State, Zip
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer
Top Expert 2015
Commented:
Hi,

Check this code. Make sure you have all the values else you will get Index Error.
   
@{
        var address = "adressline 1 | adress line 2 | City | State | zip";
        string[] arr = address.Split('|');

        <p>@arr[0]</p>
        <p>@arr[1]</p>
        <p>@arr[2], @arr[3], @arr[4]</p>
    }

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial