it doesen mater if arrayToCompareTo is a comma seperatede string .Contains will just look for the "variable" in the string. so if variable ="Skole start"
It wil return true if arrayToCompareTo contains thats string
just one little thing more if there is only one thing in the list then it's not a comma-separated list and then it jumps over it how can I get it to print if it is true
Razor foreach
I use umbraco 4.11.5
I need a foreach loop where it compares two comma separated lists
the xml
and the second comma-separated lists are a form request
if one or more of the elements are the same, then print, but I would only have one item per child
You can split both your strings on the comma which will give you 2 array's.
Then you can compare the 2 arrays. Here is a stack overflow post about comparing 2 arrays : http://stackoverflow.com/questions/10991452/how-do-i-get-the-differences-between-two-string-arrays-in-c
Dave
Hi dawoe
I'm new in Razor
How do I convert them to array
You can do something like this:
@foreach(string variable in RQfaser.Split(","), StringSplitOptions.RemoveEmptyEntries)){
if(arrayToCompareTo.Contains(variable)){
//ok
}else{
//not in array
}
}
Hi Kim,
if arrayToCompareTo is a comma-separated how do I make it so????
Hi Kim,
Yes it works :-)
thank you
it doesen mater if arrayToCompareTo is a comma seperatede string .Contains will just look for the "variable" in the string.
so if variable ="Skole start"
It wil return true if arrayToCompareTo contains thats string
so you only have to split one of the strings
foreach(var item in @Model.Children.Where("Visible"))
{
string Sfaser = @item.faser;
foreach(string variable in @RQfaser.Split(',')){
if(Sfaser.Contains(variable)){
@item.faser
}else{}
}
}
BH, Udskoling
BH, Udskoling
Skole start, Mellem trin
and the results should be
BH, Udskoling
Skole start, Mellem trin
can you see where the problemt is??
This should help then :-)
and it did
thanks :-)
just one little thing more if there is only one thing in the list then it's not a comma-separated list and then it jumps over it how can I get it to print if it is true
Hi Kim
forget it
I reverse it and now it works as it should
a thousand thanks
is working on a reply...
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.