2014-09-25 88 views
0

我正在做一個項目,我必須在數據庫上對地址進行地址解碼,然後將結果返回到單獨的表格。用「+」字符替換http請求中的空格

我有這樣

@foreach(var row in data){ 
    https://maps.googleapis.com/maps/api/geocode/json?address="@[email protected][email protected][email protected][email protected]"&key=apikey 
} 

的請求將變成像這樣

https://maps.googleapis.com/maps/api/geocode/json?address= 「111法案街+雅各布小鎮+ AB + X1X 1X1 + CA」 &鍵= apikey

我想知道是否有一種簡單的方法來替換您在地址參數中看到的空格爲「+」c haracter。

+4

'string.Replace(「」,「+」);'? – gunr2171 2014-09-25 13:41:39

+2

使用'@ Uri.EscapeDataString(row.ADDRESS1)' – 2014-09-25 13:42:56

回答

1

我能找到我的答案。我用過:

@HttpUtility.UrlEncode(row.ADDRESS1) 

這個用+這個字符替換了空格。