我正在尝试使用护照MRZ的名字但是我在解析它时遇到了困难。我想知道这个名字。但是我得到了: -
mscorlib.dll中出现未处理的“System.ArgumentOutOfRangeException”类型异常
每当我试图得到这个名字。
这是我尝试解析的地方
if (string.IsNullOrEmpty(name) || name.Length < 44)
{ }
var nameArraySplit = name.Substring(5).Split(new[] { "<<" }, StringSplitOptions.RemoveEmptyEntries);
name = nameArraySplit.Length >= 2 ? nameArraySplit[1].Replace("<", " ") : nameArraySplit[0].Replace("<", " ");
MRZ的示例
GBRTHATCHER0368447211111119718452091
1522044E12566123BUG<<<<<<<<<<<7
CAT<<GRUMPY<MINITE<<<<<<<<<<<<
谢谢
答案 0 :(得分:1)
我猜您可以Split
而非"<"
"<<"
然后获取nameArraySplit[2]
string name = "GBRTHATCHER03684472111111197184520911522044E12566123BUG<<<<<<<<<<<7CAT<<GRUMPY<MINITE<<<<<<<<<<<< ";
var nameArraySplit = name.Substring(5).Split(new[] {"<" }, StringSplitOptions.RemoveEmptyEntries);
name = nameArraySplit.Length >= 2 ? nameArraySplit[2] : nameArraySplit[0].Replace("<", " ");
c#online:https://dotnetfiddle.net/HM1WeG
答案 1 :(得分:0)
string input = @"GBRTHATCHER03684472111111197184520911522044E12566123BUG<<<<<<<<<<<7CAT<<GRUMPY<MINITE<<<<<<<<<<<<";
string name = Regex.Match(input, @"(?i)([a-z]+)<[a-z]+<+?$").Groups[1].Value;