Hi,
Is there a string split function built into Kamailio for use in the cfg script? I'd like to split a string of key/value pairs inside the cfg script. For example: Key1=Value1;Key2=Value2; First split on ; Then on =
I think I can use the String Transformation {s.select,index,separator}, but I was hoping there is a built in function. {param.valueat,index[, delimiter]} may also be an option.
Regards,
Grant
Hi Grant,
On Thu, Dec 29, 2016 at 09:12:05AM +0000, Grant Bagdasarian wrote:
Hi,
Is there a string split function built into Kamailio for use in the cfg script? I'd like to split a string of key/value pairs inside the cfg script. For example: Key1=Value1;Key2=Value2; First split on ; Then on =
Alas, there is nothing like that. Such a function would have to return an array or arraylike structure, and outside of AVPs, there are no array primitives in native Kamailio route script.
The best you can do is:
$var(i) = 0;
while(defined $(var(str){s.select,$var(i),DELIMITER})) { $var(token) = $(var(str){s.select,$var(i),DELIMITER}); $var(i) = $var(i) + 1; }
-- Alex
Hi Alex,
Thank you for the answer. I'll do it with the string transformations.
Regards,
Grant
-----Original Message----- From: sr-users [mailto:sr-users-bounces@lists.sip-router.org] On Behalf Of Alex Balashov Sent: donderdag 29 december 2016 10:18 To: Kamailio (SER) - Users Mailing List sr-users@lists.sip-router.org Subject: Re: [SR-Users] String split function
Hi Grant,
On Thu, Dec 29, 2016 at 09:12:05AM +0000, Grant Bagdasarian wrote:
Hi,
Is there a string split function built into Kamailio for use in the cfg script? I'd like to split a string of key/value pairs inside the cfg script. For example: Key1=Value1;Key2=Value2; First split on ; Then on =
Alas, there is nothing like that. Such a function would have to return an array or arraylike structure, and outside of AVPs, there are no array primitives in native Kamailio route script.
The best you can do is:
$var(i) = 0;
while(defined $(var(str){s.select,$var(i),DELIMITER})) { $var(token) = $(var(str){s.select,$var(i),DELIMITER}); $var(i) = $var(i) + 1; }
-- Alex
-- Alex Balashov | Principal | Evariste Systems LLC
Tel: +1-706-510-6800 (direct) / +1-800-250-5920 (toll-free) Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
_______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users