Gibt es einen "reinen Linq" -Scharakter, um eine Abkürzung von zwei Buchstaben in der Stadt zu erstellen?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Gibt es einen "reinen Linq" -Scharakter, um eine Abkürzung von zwei Buchstaben in der Stadt zu erstellen?

by Anonymous » 02 May 2025, 07:47

Mein aktueller Code ist dies. Aber ich würde gerne mehr linq -zentrische Muster für solche Dinge lernen < /p>

Code: Select all

string city, cityAbbr;

city = "SANTA FE";

cityAbbr = city.IndexOf(' ') == -1 ? city.Substring(0,2) : new string(city.Split(' ').Select(s => s[0]).ToArray());

// SF

city = "CHICAGO";
cityAbbr = city.IndexOf(' ') == -1 ? city.Substring(0,2) : new string(city.Split(' ').Select(s => s[0]).ToArray());

// CI

Top