Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
December 11, 2018 How to split strings into AA using phobos | ||||
---|---|---|---|---|
| ||||
A typical example would be to split the HTTP query string into an AA. vibe.d has req.queryString, but no convenient wrapper to access it as an AA. http://localhost/hello?name=abc&id=123 I've got this far. auto arr = req.queryString.splitter('&').map!(a => a.splitter('=')); Thanks |
December 11, 2018 Re: How to split strings into AA using phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Arun Chandrasekaran | On Tuesday, 11 December 2018 at 08:20:32 UTC, Arun Chandrasekaran wrote: > A typical example would be to split the HTTP query string into an AA. > > vibe.d has req.queryString, but no convenient wrapper to access it as an AA. > > http://localhost/hello?name=abc&id=123 > > I've got this far. > > auto arr = req.queryString.splitter('&').map!(a => a.splitter('=')); > > Thanks req.queryString[req.queryString.indexOf('?') + 1 .. $] .splitter('&') .map!(a => a.splitter('=')) .map!(a => tuple(a.front, a.back)) .assocArray |
December 11, 2018 Re: How to split strings into AA using phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Arun Chandrasekaran | On Tuesday, 11 December 2018 at 08:20:32 UTC, Arun Chandrasekaran wrote:
> A typical example would be to split the HTTP query string into an AA.
>
> vibe.d has req.queryString, but no convenient wrapper to access it as an AA.
>
> http://localhost/hello?name=abc&id=123
>
> I've got this far.
>
> auto arr = req.queryString.splitter('&').map!(a => a.splitter('='));
>
> Thanks
I am not 100% sure but I think query parameters names can occur multiple times in query string.
Therefore you need an associative array with string as key and string[] array as value.
By using associative array you loose the order of the parameters. Whether this is important for query parameters I do not know.
Kind regards
Andre
|
December 11, 2018 Re: How to split strings into AA using phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | On Tuesday, 11 December 2018 at 18:46:27 UTC, Andre Pany wrote:
> I am not 100% sure but I think query parameters names can occur multiple times in query string.
Yes, that's right.
|
December 11, 2018 Re: How to split strings into AA using phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Arun Chandrasekaran | On 12/11/18 3:20 AM, Arun Chandrasekaran wrote: > A typical example would be to split the HTTP query string into an AA. > > vibe.d has req.queryString, but no convenient wrapper to access it as an AA. Yeah it does: http://vibed.org/api/vibe.http.server/HTTPServerRequest.query -Steve |
Copyright © 1999-2021 by the D Language Foundation