question

ozkaro-7807 avatar image
0 Votes"
ozkaro-7807 asked TimonYang-MSFT commented

how to compare chars of one string to other in any order?

Hi I'm trying to compare char's of one string to other chars on other string but i can't get any good result, what I want to do is something like this

"apem" compare on any order in "sample"

I have a dictionary and i want to return all text wich contains what I'm comparing in a list

 foreach (var s in squery ?? new List<DictDatabase>())
                 {
                     if (s != null)
                     {
                         if (!string.IsNullOrEmpty(s.components))
                         {
                             if (s.components.All(j => j.Equals(compare.ToCharArray())))
                             {
                                 DictList.Add(s);
                             }
                             else if(s.components.Contains(compare))
                             {
                                 DictList.Add(s);
                             }
                         }
                     }
                 }

the "else if(s.components.Contains" just return a list with the first char what I'm writing, if I enter another char it doesn't return nothing
the "if(s.components.All" statement doesn't anything

dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ozkaro-7807
Could you please provide more complete information, what did the data originally look like, and what should the expected result be? I don't quite understand what you mean now.

0 Votes 0 ·
ozkaro-7807 avatar image
0 Votes"
ozkaro-7807 answered

thanks @Viorel-1 but this code just return one item in the dictionary by character writed

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Try if(s.components.All(compare.Contains)) or maybe if(compare.All(s.components.Contains)) depending on meaning of these variables.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.