首页  编辑  

经纬度换算

Tags: /C#/算法/   Date Created:

using System . Text . RegularExpressions;

static string Calc( string AParam)

{

    Match vMatch = Regex . Match(AParam, "([0-9]+)°" );

    double A = 0 ;

    if (vMatch . Success) A = double . Parse(vMatch . Result( "$1" ));

   vMatch = Regex . Match(AParam, "([0-9]+) );

    double B = 0 ;

    if (vMatch . Success) B = double . Parse(vMatch . Result( "$1" ));

   vMatch = Regex . Match(AParam, "([0-9]+) );

    double C = 0 ;

    if (vMatch . Success) C = double . Parse(vMatch . Result( "$1" ));

    return string . Format( "{0:.000}" , A + B / 60 + C / 3600 );

}

static void Main( string [] args)

{

    Console . WriteLine( @"110°3= " + Calc( @"110°3 ));

    Console . WriteLine( @"110°7= " + Calc( @"110°7 ));

    Console . ReadKey();

}