Community discussions

MikroTik App
 
tabraham
newbie
Topic Author
Posts: 27
Joined: Wed Feb 08, 2017 10:18 pm
Location: Germany
Contact:

String Split to array

Tue Oct 10, 2023 8:54 pm

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
	}
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12445
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: String Split to array

Thu Oct 12, 2023 10:41 am

there is a prebuild function
No.

:find "->" and :pick the right parts.
For multiple array, run multiple times.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4143
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: String Split to array

Thu Oct 12, 2023 6:16 pm

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.

Who is online

Users browsing this forum: No registered users and 7 guests