How to split string in MVC view

Home > Search > How-to
  by

In this example, we create a varable called MyString that contains the text "Hellow from MVC application." We then split the string, where a single space is the delimiter. Finally, we use a foreach loop to iterate through each word that was split.

@{
    string MyString = "Hello from MVC application";
    string[] SplitString = MyString.Split(' ');

    foreach (string words in SplitString)
    {
        <p>@words</p>
    }
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments