Page 1 of 1

String Split to array

Posted: Tue Oct 10, 2023 8:54 pm
by tabraham
Hi I was wondering is there is a prebuild function or a script which can split strings to arrays for a given operator?
ex: "5489->12->59->15663" this will have the split operator "->" and the output will be an array of 
{
	5489
	12
	59
	15663
}
More complex (array of array)
ex: "5489->12;59->15663" this will have the split operators ";" and "->" and the output will be an array of
{
	{
		5489
		12
	}
	{
		59
		15663
	}
}

Re: String Split to array

Posted: Thu Oct 12, 2023 10:41 am
by rextended
there is a prebuild function
No.

:find "->" and :pick the right parts.
For multiple array, run multiple times.

Re: String Split to array

Posted: Thu Oct 12, 2023 6:16 pm
by Amm0
Yup, the only "built-in split()" is via :toarray which works with comma-separated values.

In generally, it best to do data parsing before it get's to the Mikrotik, since there aren't good primitives like splice(), split(), trim(), etc.... There is just :find and :pick as @rextended explains - which is the basic building block of any of those, so possible, just tedious.