我有以下输入:
(FPL-XXXXX-IG
-GLF5/M-SDE2E3FGHIRWXY/E
-ABCD0300
-N0292F060 UPTON1C UPTON/N0447F430 UL975 BARTN UP17 NOKIN UN862
RILES UL180 MERLY DCT GAPLI/M080F430 DCT 46N015W 45N020W/M080F470
37N030W 33N040W 26N050W 18N058W/N0448F470 DCT BNE DCT
-EFGH0933 IJKL
-PBN/A1B1C1D1 DOF/141218 REG/XXXXX
EET/EISN0114 EGGX0132 LPPO0239 KZWY0526 TTZP0830
46N015W0208 45N020W0239 37N030W0410 33N040W0526
SEL/TEST ORGN/KHOUUVAX PER/C
E/1128 P/TBN R/UVE D/2 10 YELLOW A/RED WHITE BLUE C/TBN)
我希望第三行以短划线(N0292F060
)开头,直到从短划线开始的下一行开头(-EFGH0933
)。
理想输出为"N0292F060 UPTON1C UPTON/N0447F430 UL975 BARTN UP17 NOKIN UN862 RILES UL180 MERLY DCT GAPLI/M080F430 DCT 46N015W 45N020W/M080F470 37N030W 33N040W 26N050W 18N058W/N0448F470 DCT BNE DCT".
如何弄清楚?
答案 0 :(得分:2)
您可以使用String.split()函数,该函数接受您要用作拆分标志的字符数组。 在您的问题中,您希望根据 - 字符拆分字符串,如果这有意义并且有效,请参阅以下代码。
char[] delimiter = {'-'};
String[] arr = data.Split(delimiter,StringSplitOptions.None);
Console.WriteLine(arr[6]);
//this will return the following string
/*
N0292F060 UPTON1C UPTON/N0447F430 UL975 BARTN UP17 NOKIN UN862
RILES UL180 MERLY DCT GAPLI/M080F430 DCT 46N015W 45N020W/M080F470
37N030W 33N040W 26N050W 18N058W/N0448F470 DCT BNE DCT*/
答案 1 :(得分:0)
这是你可以做的事情,让你开始..
var spltLargString = yourString.Replace("(", "");
var spltArray = spltLargString.Split(new[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
`从这里开始,您需要编写自己的解析代码或条件检查,以便在必要时评估数据。
Below is a string representation of the above
var spltLargString = "(FPL-XXXXX-IG-GLF5/M-SDE2E3FGHIRWXY/E-ABCD0300-N0292F060 UPTON1C UPTON/N0447F430 UL975 BARTN UP17 NOKIN UN862RILES UL180 MERLY DCT GAPLI/M080F430 DCT 46N015W 45N020W/M080F47037N030W 33N040W 26N050W 18N058W/N0448F470 DCT BNE DCT-EFGH0933 IJKL-PBN/A1B1C1D1 DOF/141218 REG/XXXXXEET/EISN0114 EGGX0132 LPPO0239 KZWY0526 TTZP083046N015W0208 45N020W0239 37N030W0410 33N040W0526SEL/TEST ORGN/KHOUUVAX PER/CE/1128 P/TBN R/UVE D/2 10 YELLOW A/RED WHITE BLUE C/TBN)".Replace("(", "").Replace(")","");
var spltArray = spltLargString.Split(new[] { "-" }, StringSplitOptions.RemoveEmptyEntries);