Esto es lo que estoy tratando de hacer. Tengo una lista de Tstring, por un nombre. Si el nombre está en un formato DOE, JOHN, NMI, quiero que divida el nombre en 3 cadenas diferentes.
Pero el problema es, ¿y si no hay inicial del segundo. O el primer nombre. Al igual que podría ser solo DOE, entonces las últimas dos líneas están fuera de límites. Y el programa se cuelga. ¿Cuál es la mejor solución?Cómo comprobar longitud de TStringList en Delphi
var ptname, physname: Tstringlist;
if pos(',',Msg.Grp2[0].ObsReq[0].OrderingProviderFamilyName) > 0 then // split it if it has a comma
begin
physname := TstringList.Create;
physname.CommaText := Msg.Grp2[0].ObsReq[0].OrderingProviderFamilyName;
Parameters.ParamByName('@OrderingLastNameOBR16').Value := physname[0];
Parameters.ParamByName('@OrderingFirstNameOBR16').Value := physname[1];
Parameters.ParamByName('@OrderingMiddleNameOBR16').Value := physname[2];
physname.Free;
end
buena solución a un lado de David, sería más limpio para tener una CSV totalmente lleno. Si falta un elemento, solo tiene comas. ejemplo: DOE DOE sería ,, entonces todavía divide bien sin tener que perder el tiempo. –
@Chris: David? David, ¿quién? Harumph! : P – dthorpe