I'm writing a c# console program that reads a configuration file and a google map example found in google dev website.. I copied the html content into a local template file and put placeholders for string.format
(notice the {1}, {2} in code snipped below.
I then read the template from the local file system and use the code below to populate the placeholders. The problem is that the string.format
keeps throwing error saying Input string was not in a correct format.
If I replace the template with a blank file, the Input string was not in a correct format.
is not thrown. There are no exceptions. Thus, the problem is with the html template below and not the code. Can someone spot the issue with the template that make so that it doesn't work with string.format
? I'm guessing that it has to do with {
and }
so I moved around any double (i.e. {{
) but that didn't help.
Code
var res = string.Format(template,
ConfigurationManager.AppSettings["PageTitle"],
ConfigurationManager.AppSettings["zoom"],
ConfigurationManager.AppSettings["CenterLat"],
ConfigurationManager.AppSettings["CenterLongi"],
ConfigurationManager.AppSettings["mapTypeId"],
sb.ToString(),
ConfigurationManager.AppSettings["strokeColor"],
ConfigurationManager.AppSettings["strokeOpacity"],
ConfigurationManager.AppSettings["strokeWeight"],
ConfigurationManager.AppSettings["fillColor"],
ConfigurationManager.AppSettings["fillOpacity"],
ConfigurationManager.AppSettings["GoogleMapBaseUrl"].Replace("_KEY_", ConfigurationManager.AppSettings["APIKey"])
);
HTML Template
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>{0}</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: {1},
center: {
lat: {2}, lng: {3}
},
mapTypeId: {4}
});
// Define the LatLng coordinates for the polygon's path.
var triangleCoords = [
{5}
];
// Construct the polygon.
var bermudaTriangle = new google.maps.Polygon(
{
paths: triangleCoords,
strokeColor: '{6}',
strokeOpacity: {7},
strokeWeight: {8},
fillColor: '{9}',
fillOpacity: {10}
});
bermudaTriangle.setMap(map);
}
</script>
<script async defer
src="{11}"></script>
</body>
</html>