Copied to clipboard

Flag this post as spam?

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


  • Kerri Mallinson 113 posts 497 karma points
    Aug 28, 2014 @ 18:37
    Kerri Mallinson
    0

    incasesensitive replace in search results

    Hi,

    Using 7.1.4

    Does anyone know how i can make the following ignore casing?

    @Html.Raw(result["copy"].Replace(searchTerm , "<strong>" + searchTerm + "</strong>").Truncate(200))
    

    Thanks

    p.s. @using Examine.LuceneEngine.SearchCriteria

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Aug 28, 2014 @ 19:24
    Dennis Aaen
    0

    Hi Kerri,

    To ignore case you should be able to use the ToLower() method. What if you do something like this:

    @Html.Raw(result["copy"].Replace(searchTerm.ToLower() ,"<strong>"+ searchTerm.ToLower() +"</strong>").Truncate(200))

    Hope this helps,

    /Dennis

  • Kerri Mallinson 113 posts 497 karma points
    Aug 28, 2014 @ 20:00
    Kerri Mallinson
    0

    Hi Dennis,

    Thanks but it didn't work :( If i lower all the copy like below the replace works but obviously it lower cases all the text which I don't want

    @Html.Raw(result["copy"].ToLower().Replace(searchTerm ,"<strong>"+ searchTerm +"</strong>").Truncate(200))

    I didn't know if there was some way of using Regex.Replace, I've tried the below but no luck

    @Html.Raw(result["copy"].Regex.Replace(searchTerm , "<strong>"+ searchTerm +"</strong>", RegexOptions.IgnoreCase).Truncate(200))
    

    Thanks

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Aug 28, 2014 @ 20:28
    Dennis Aaen
    0

    Hi Kerri,

    I think that you are on the right track with this one:

    @Html.Raw(result["copy"].Regex.Replace(searchTerm ,"<strong>"+ searchTerm +"</strong>",RegexOptions.IgnoreCase).Truncate(200))

    Could the reason why your code doesn't work, is because that you don't have an regex. Or did the serachTerm contains a regex.

    Maybe this post can help you to get the syntax right, I hope so

    http://our.umbraco.org/forum/developers/razor/28100-regular-expression-help

    /Dennis

  • Kerri Mallinson 113 posts 497 karma points
    Aug 28, 2014 @ 21:10
    Kerri Mallinson
    0

    Thanks Dennis,

    I don't know anything about Regex so i'll have to do some research!

    The code just gives me: Error loading Partial View script (file: ~/Views/MacroPartials/SearchResults.cshtml)

    Thanks again anyway

    Kerri

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies