Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
you could try
x.Value<string[]>("topicTags").Select(s => s.ToLowerInvariant()).ToArray().Contains(@myLowercaseTag)
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
you are basically just creating a new array from your existing array by selecting each element s => s and lowercasing it
s => s
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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
Suggestions how to transform the topicTags and locationTags arrays to lower case will be much appreciated.
Thanks Jesper
you could try
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
you are basically just creating a new array from your existing array by selecting each element
s => s
and lowercasing itis working on a reply...