Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Raja 11 posts 81 karma points notactivated
    May 11, 2016 @ 09:41
    Raja
    0

    splitting the text string by Numbers wise

    Hi ,

    I am having the string data in database table like this 1. Spray directly onto the surface to be cleaned. 2. Leave for one minute. 3. Wipe with a damp cloth. 4. At kraftgit ingrained dirt, work the surface with a cloth and rinse with water. Do not let the product dry on the surface being treated. 5. To clean plastic or painted surfaces diluted product: 30 ml to 4 liters of water. 6. When used on carpets or fabric, first test on a hidden surface.

    i want to display in view like this :

    1. Spray directly onto the surface to be cleaned.
    2. Leave for one minute.
    3. Wipe with a damp cloth.
    4. At kraftgit ingrained dirt, work the surface with a cloth and rinse with water. Do not let the product dry on the surface being treated.
    5. To clean plastic or painted surfaces diluted product: 30 ml to 4 liters of water.
    6. When used on carpets or fabric, first test on a hidden surface.

    is there any possibility to achieve my way help me if any one knows.

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    May 11, 2016 @ 10:00
    Dennis Adolfi
    0

    Hello Raja.

    Maybe you could do a helper in your view like:

    @helper FormatStringAsNumberList(string source)
    {
        for (int i = 1; i <= 6; i++)
        {
            var separator = i + ".";
            source = source.Replace(separator, "<br/>" + separator);
        }
    
        @Html.Raw(source)
    }
    

    And calling it like:

    @FormatStringAsNumberList(stringData)
    

    Where stringData is your string from the database. You can offcource change the number 6 in the for loop if you know there is going to be more than one list item.

    Off cource this is not bulletproof since there is always the possibility that a user (i just assume the string data is editable) uses a number followed by a . in an actual line, but its A way.

    Best of luck to you!!

  • Casper 70 posts 308 karma points
    May 11, 2016 @ 10:36
    Casper
    1

    Another way to go could be:

            var input = "1. Spray directly onto the surface to be cleaned. 2. Leave for one minute. 3. Wipe with a damp cloth. 4. At kraftgit ingrained dirt, work the surface with a cloth and rinse with water. Do not let the product dry on the surface being treated. 5. To clean plastic or painted surfaces diluted product: 30 ml to 4 liters of water. 6. When used on carpets or fabric, first test on a hidden surface. 7. ";
            var pattern = @"(\d\.)"; // encapsulate pattern in parenthesis and the "splitted by" part will also be returned
            var values = Regex.Split(input, pattern).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
            var result = new List<string>();
            for (var i = 0; i < values.Length; i++)
            {
                if (i + 1 >= values.Length)
                    continue;
                if (i % 2 == 0)
                    result.Add(values[i] + values[i + 1]);
    
            }
            var readable = string.Join("<br>", result).ToArray();
    
Please Sign in or register to post replies

Write your reply to:

Draft