convert Javascript function to c#
<p>I want to convert following javascript function to c#
can anyone help?</p>

<pre><code>function parseCoordinate(coordinate,type,format,spaced) {
    coordinate = coordinate.toString();
    coordinate = coordinate.replace(/(^\s+|\s+$)/g,''); // remove white space
    var neg = 0; if (coordinate.match(/(^-|[WS])/i)) { neg = 1; }
    if (coordinate.match(/[EW]/i) &amp;&amp; !type) { type = 'lon'; }
    if (coordinate.match(/[NS]/i) &amp;&amp; !type) { type = 'lat'; }
    coordinate = coordinate.replace(/[NESW\-]/gi,' ');
    if (!coordinate.match(/[0-9]/i)) {
        return '';
    }
    parts = coordinate.match(/([0-9\.\-]+)[^0-9\.]*([0-9\.]+)?[^0-9\.]*([0-9\.]+)?/);
    if (!parts || parts[1] == null) {
        return '';
    } else {
        n = parseFloat(parts[1]);
        if (parts[2]) { n = n + parseFloat(parts[2])/60; }
        if (parts[3]) { n = n + parseFloat(parts[3])/3600; }
        if (neg &amp;&amp; n &gt;= 0) { n = 0 - n; }
        if (format == 'dmm') {
            if (spaced) {
                n = Degrees_to_DMM(n,type,' ');
            } else {
                n = Degrees_to_DMM(n,type);
            }
        } else if (format == 'dms') {
            if (spaced) {
                n = Degrees_to_DMS(n,type,' ');
            } else {
                n = Degrees_to_DMS(n,type,'');
            }
        } else {
            n = Math.round(10000000 * n) / 10000000;
            if (n == Math.floor(n)) { n = n + '.0'; }
        }
        return comma2point(n);
    }
}
</code></pre>
