How do I excape out " in a string?

netchicken

Active Member
Licensed User
Longtime User
I need to surround the newaddress variable with " " in the following url.

weatherurl = "http://maps.googleapis.com/maps/api/geocode/xml?address=" & newaddress & "&sensor=False"

I used Chr(34) as a replacement in
weatherurl = "http://maps.googleapis.com/maps/api/geocode/xml?address="& Chr(34)& newaddress & Chr(34)&"&sensor=False"

Which generated the correct string but then I don't think the weatherurl variable could hold it to put it into the following

request.InitializeGet(weatherurl)

The java error said it had an illegal character in the query at index 56 which is right where the " is.

I tried request.InitializeGet("http://maps.googleapis.com/maps/api/geocode/xml?address="& Chr(34)& newaddress & Chr(34)&"&sensor=False")

but it just barfed again.

Any ideas?
 
Last edited:

netchicken

Active Member
Licensed User
Longtime User
Nope
It needs to have the address surrounded with the " " probably because it doesn't like the blanks.

Using %22 or %20 doesn't parse them as " or blank, it just messes up the string.

This below works when pasted directly into the browser but it does seem to need the quotes to isolate the address.
http://maps.googleapis.com/maps/api/geocode/xml?address="Your Address Here"&sensor=False

Google example shows + as a placeholder for the space, but that doesn't work either

Even QUOTE doesn't work
I still get the IllegalArgumentException Illegal character in query even though the output looks perfect.

I think it hates it when it gets to here
request.InitializeGet(weatherurl)

I tried dicing the url up like this
request.InitializeGet(weatherurla &QUOTE& newaddress &QUOTE& weatherurlb)

but still no luck

Have any other people solved the problem of " in urls?
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Try this:

B4X:
Sub Globals

    Dim su As StringUtils '<--- String Utils Library

End Sub

...

weatherurl = "http://maps.googleapis.com/maps/api/geocode/xml?address=" & newaddress & "&sensor=False"

weatherurl = su.EncodeUrl(weatherurl, "UTF8")

I haven't tested that myself, but probably it needs to be URL Encoded. Give that a shot.
 
Upvote 0

netchicken

Active Member
Licensed User
Longtime User
Thanks for that NJDude, but it turned my url into a wild and crazy thang.

The // and . all became %3A and %2F type characters

The url looks OK with QUOTE & newaddress & QUOTE in it its just not working when put into

request.InitializeGet(weatherurl)
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User

Well yes, the URL will look coo-coo but that's what URL encoding is all about, some services (not sure about this weather thing) require URL encoding, I have a question for you, what is the problem you are having? not able to send that string or unable the parse the result?
 
Upvote 0

netchicken

Active Member
Licensed User
Longtime User
Thanks admac231, that works!!!!!

For anyone who wants to use it it looks like this.....
B4X:
 newaddress = edtaddress.Text
newaddress = newaddress.Replace(" ","+")
addressurl= "http://maps.googleapis.com/maps/api/geocode/xml?address=" & newaddress & "&sensor=false"
request.InitializeGet(addressurl)

NJdud the problem was getting past the request.InitializeGet(addressurl) part.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…