gpt4 book ai didi

c# - 寻找一种更灵活的方法将定界字符串转换为 StringDictionary

转载 作者:太空狗 更新时间:2023-10-29 23:10:14 25 4
gpt4 key购买 nike

我创建了以下内容以将一些数据公开为正则表达式匹配字符串和 StringDictionary。感觉我可以用更少的行数使用 LINQ 来做到这一点。

private const string STREETTYPES = @"ALY|Alley|AVE|Avenue|BLVD|Boulevard|CIR|Circle|CT|Court|CTR|Center|DR|Drive|EXPY|Expressway|FWY|Freeway|HALL|Hall|HWY|Highway|JCT|Junction|LN|Lane|LP|Loop|PIKE|Pike|PKWY|Parkway|PL|Place|RD|Road|ST|Street|TER|Terrace|TPKE|Turnpike|TRL|Trail|WAY|Way";

private static StringDictionary streetTypes = null;
public static StringDictionary StreetTypes
{
get
{
if (streetTypes != null) return streetTypes;
streetTypes = new StringDictionary();
var streetArray = STREETTYPES.Split(PIPE);
for (int i = 0; i < streetArray.Length-1; i = i+2)
{
streetTypes.Add(streetArray[i], streetArray[i + 1]);
}
return streetTypes;
}
}

最佳答案

怎么样:

private static readonly StringDictionary streetTypes = new StringDictionary
{
{"ALY","Alley"},{"AVE","Avenue"},{"ALY","Alley"},{"BLVD","Boulevard"},{"CIR","Circle"},
{"CT","Court"},{"CTR","Center"},{"DR","Drive"},{"EXPY","Expressway"},{"FWY","Freeway"},
{"HALL","Hall"},{"HWY","Highway"},{"JCT","Junction"},{"LN","Lane"},{"LP","Loop"},
...
};

关于c# - 寻找一种更灵活的方法将定界字符串转换为 StringDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7733208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com