I am a bit puzzled about the results of these tests and the fact that in one of the tests .Split(' ').Last() not working.
I have the following:
print("1) " + "Lidingö kommun Sverige".Split(' ').Last());
string xx = "Lidingö kommun Sverige";
print("2) " + xx.Split(' ').Last());
print("3) " + Utility.setup_List[0].freqFullLocationName);
print("4) " + Utility.setup_List[0].freqFullLocationName.Split(' ').Last());
The Utility.setup_List[0].freqFullLocationName is a string.
I get the following results:
1) Sverige
2) Sverige
3) Lidingö kommun Sverige
4)
Given that the Utility.setup_List[0].freqFullLocationName is a string I do not understand why it is not split correct. I have tested to first copy to a new string and then split with the same result.
>Solution :
The content of freqFullLocationName is "Lidingö kommun Sverige " with a space at the end.
So, Split() works as expected because it it recognizes the space and splits "Sverige" from an empty string entry after the following space.
If you want to fix this behavior, you can specify the StringSplitOptions.RemoveEmptyEntries option when calling Split(). Or use Trim() on the string before calling Split().
print("4) " + Utility.setup_List[0].freqFullLocationName.
Split(' ', StringSplitOptions.RemoveEmptyEntries).Last());