Copied to clipboard

Flag this post as spam?

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


  • Jesper Skjønnemand 66 posts 441 karma points c-trib
    Dec 08, 2022 @ 12:22
    Jesper Skjønnemand
    0

    transform array to lower case

    I want to make a selection of pages based on their tags, here named topicTags and locationTags, and a "lookup" word that the editor enters.

    Currently the result is case sensitive, i.e. when I look for "test" I get pages with the tag "test" but not "Test" or "TEST".

    I guess transforming everything to lower case is the way forward.

    The "lookup" word entered by the editor @myTag is transformed to @myLowercaseTag using ToLower(). Easy enough.

    But I can't seem to get the correct syntax to transform the arrays of tags.

    I have this

    .Where(x => x.Value<string[]>("topicTags").Contains(@myLowercaseTag) || x.Value<string[]>("locationTags").Contains(@myLowercaseTag))
    

    Suggestions how to transform the topicTags and locationTags arrays to lower case will be much appreciated.

    Thanks Jesper

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Dec 08, 2022 @ 12:25
    Huw Reddick
    100

    you could try

    x.Value<string[]>("topicTags").Select(s => s.ToLowerInvariant()).ToArray().Contains(@myLowercaseTag)
    
  • Jesper Skjønnemand 66 posts 441 karma points c-trib
    Dec 08, 2022 @ 12:42
    Jesper Skjønnemand
    0

    Thank you very much, Huw. This actually works.

    I will go study a bit to understand how the .Select(s => s.ToLowerInvariant()).ToArray() string works.

    Best wishes Jesper

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Dec 08, 2022 @ 12:47
    Huw Reddick
    0

    you are basically just creating a new array from your existing array by selecting each element s => s and lowercasing it

Please Sign in or register to post replies

Write your reply to:

Draft