type
TGeoData = record
NSOrientation: char;
NSDegree: integer;
NSMinutes: string;
EWOrientation: char;
EWDegree: integer;
EWMinutes: string;
end;
const
DEGREESIGN = '°';
ORIGINAL = 'N 49° 8.66 E 8° 1.72';
var
CurrentPos, NextPos: integer;
Data: TGeoData;
GeoData, s: string;
tempstr : String;
pos1 : Integer;
begin
DecimalSeparator := '.';
ZeroMemory(@Data, SizeOf(Data));
GeoData := StringReplace(ORIGINAL, ' ', '', [rfReplaceAll]);
Data.NSOrientation := GeoData[1];
CurrentPos := 2;
NextPos := Pos(DEGREESIGN, GeoData);
Data.NSDegree := StrToInt(Copy(GeoData, CurrentPos, NextPos - CurrentPos));
CurrentPos := NextPos + 1;
NextPos := PosEx('E', AnsiUpperCase(GeoData), CurrentPos);
if NextPos = 0 then
NextPos := PosEx('W', AnsiUpperCase(GeoData), CurrentPos);
TempStr := Copy(GeoData, CurrentPos, NextPos - CurrentPos);
pos1 := pos('.',TempStr);
if pos1 = 2 then
insert('0',tempstr,1);
pos1 := pos('.',TempStr);
if (pos1 = 3) and (length(tempstr)=5) then
insert('0',tempstr,4);
data.nsminutes := tempstr;
CurrentPos := NextPos + 1;
Data.EWOrientation := GeoData[NextPos];
NextPos := PosEx(DEGREESIGN, GeoData, CurrentPos);
Data.EWDegree := StrToInt(Copy(GeoData, CurrentPos, NextPos - CurrentPos));
CurrentPos := NextPos + 1;
TempStr := Copy(GeoData, CurrentPos, MAXINT);
pos1 := pos('.',TempStr);
if pos1 = 2 then
insert('0',tempstr,1);
pos1 := pos('.',TempStr);
if (pos1 = 3) and (length(tempstr)=5) then
insert('0',tempstr,4);
Data.EWMinutes := tempstr;
s := Format('%s %.2d%s %s %s %.3d%s %s', [
Data.NSOrientation,
Data.NSDegree,
DEGREESIGN,
Data.NSMinutes,
Data.EWOrientation,
Data.EWDegree,
DEGREESIGN,
Data.EWMinutes]);
ShowMessage(s);
end;