Page 1 of 1

variation of string.split w/o delimiters?

Posted: Mon Sep 09, 2013 5:45 pm
by TheUltimateMap
Hello

I would like to split a line into parts that are 2 characters long each. There is no delimiter in between these parts though. So something like

xxyyzz

I want to capture xx, yy, and zz...

It may be possible for me to create an echo from the line that adds delimiters and capture from that instead, but I am avoiding this as it may affect other functionality in my script and I'm hoping there is a more simple way to extract what I need.

Any suggestions?

Re: variation of string.split w/o delimiters?

Posted: Mon Sep 09, 2013 6:51 pm
by Jor'Mox
You could do a loop sort of like this:
Code: [show] | [select all] lua
local string_in = "xxyyzz"
local string_table = {}
local index = 1
repeat
	string_table[index] = string.sub(string_in,0,2)
	string_in = string.sub(string_in,3)
	index = index + 1
until #string_in == 0