我在写C#的方法是转换机场滑行道从他们的orignial格式的书面出来的版本之中......这样的例子:解析机场滑行道标签
AA
将写作ALPHA ALPHA
F1
为FOXTROT 1
看看更多的例子洛杉矶机场图:https://www.dropbox.com/s/8614gp41dwnwvsm/klax.PDF
这是我迄今为止:
public static string ParseTaxiway(string taxiway)
{
string twy = "";
var alpha = Regex.Match(taxiway, "([A-Z]){1,2}");
var alphanum = Regex.Match(taxiway, "([A-Z])([1-9])");
// do we have an alpha character only taxiway?
if(alpha.Success)
{
switch(alpha.Groups[1].Value)
{
case "A":
twy = "ALPHA";
break;
case "B":
twy = "BRAVO";
break;
case "C":
twy = "CHARLIE";
break;
case "D":
twy = "DELTA";
break;
case "E":
twy = "ECHO";
break;
case "F":
twy = "FOXTROT";
break;
case "G":
twy = "GOLF";
break;
case "H":
twy = "HOTEL";
break;
case "I":
twy = "INDIA";
break;
case "J":
twy = "JULIET";
break;
case "K":
twy = "KILO";
break;
case "L":
twy = "LIMA";
break;
case "M":
twy = "MIKE";
break;
case "N":
twy = "NOVEMBER";
break;
case "O":
twy = "OSCAR";
break;
case "P":
twy = "PAPA";
break;
case "Q":
twy = "QUEBEC";
break;
case "R":
twy = "ROMEO";
break;
case "S":
twy = "SIERRA";
break;
case "T":
twy = "TANGO";
break;
case "U":
twy = "UNIFORM";
break;
case "V":
twy = "VICTOR";
break;
case "W":
twy = "WHISKEY";
break;
case "X":
twy = "XRAY";
break;
case "Y":
twy = "YANKEE";
break;
case "Z":
twy = "ZULU";
break;
}
}
// taxiway with letter and number; A1, F5, B6, etc
if(alphanum.Success)
{
switch (alphanum.Groups[1].Value)
{
case "A":
twy = "ALPHA " + alphanum.Groups[2].Value);
break;
case "B":
twy = "BRAVO " + alphanum.Groups[2].Value);
break;
case "C":
twy = "CHARLIE " + alphanum.Groups[2].Value);
break;
case "D":
twy = "DELTA " + alphanum.Groups[2].Value);
break;
case "E":
twy = "ECHO " + alphanum.Groups[2].Value);
break;
case "F":
twy = "FOXTROT " + alphanum.Groups[2].Value);
break;
case "G":
twy = "GOLF " + alphanum.Groups[2].Value);
break;
case "H":
twy = "HOTEL " + alphanum.Groups[2].Value);
break;
case "I":
twy = "INDIA " + alphanum.Groups[2].Value);
break;
case "J":
twy = "JULIET " + alphanum.Groups[2].Value);
break;
case "K":
twy = "KILO " + alphanum.Groups[2].Value);
break;
case "L":
twy = "LIMA " + alphanum.Groups[2].Value);
break;
case "M":
twy = "MIKE " + alphanum.Groups[2].Value);
break;
case "N":
twy = "NOVEMBER " + alphanum.Groups[2].Value);
break;
case "O":
twy = "OSCAR " + alphanum.Groups[2].Value);
break;
case "P":
twy = "PAPA " + alphanum.Groups[2].Value);
break;
case "Q":
twy = "QUEBEC " + alphanum.Groups[2].Value);
break;
case "R":
twy = "ROMEO " + alphanum.Groups[2].Value);
break;
case "S":
twy = "SIERRA " + alphanum.Groups[2].Value);
break;
case "T":
twy = "TANGO " + alphanum.Groups[2].Value);
break;
case "U":
twy = "UNIFORM " + alphanum.Groups[2].Value);
break;
case "V":
twy = "VICTOR " + alphanum.Groups[2].Value);
break;
case "W":
twy = "WHISKEY " + alphanum.Groups[2].Value);
break;
case "X":
twy = "XRAY " + alphanum.Groups[2].Value);
break;
case "Y":
twy = "YANKEE " + alphanum.Groups[2].Value);
break;
case "Z":
twy = "ZULU " + alphanum.Groups[2].Value);
break;
}
}
return twy;
}
我与此遇到的问题是,如果我有一个滑行道标记AA
,它只会返回ALPHA
。滑行道限制为一个或两个字母长或带一个数字(1-9)的一个字母。 R,AA,AC,D1,ZZ等等,所以有很多组合。
如果有人能指导我正确地创建这个解析方法的正确路径,我将不胜感激。
伟大的工程...但是,我现在的问题(我应该包括在我原来的问题中)是如果我有一个句子的滑行道。例如'TWY C5 CLSD。 TWY C10 AND TWY C5 CLSD' ...我想改写成TWY CHARLIE 5 CLSD。 TWY CHARLIE 10和TWY CHARLIE 5 CLSD' – Zach
@Zach 1.将'if'条件的否定取出到一个单独的IsMatch方法中,该方法接受一个字符串并返回一本书。 2.将你的句子拆分为空格字符。 3.对于每个拆分字符串,如果它是IsMatch,请将其替换为Parse。 4.用空格连接拆分字符串以重建句子。 –
@Zach此外,您的示例引用了与您的规格不符的“C10”。 –