variation of string.split w/o delimiters?

Post Reply
TheUltimateMap
Posts: 10
Joined: Thu Jul 11, 2013 9:14 pm

variation of string.split w/o delimiters?

Post 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?

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

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

Post 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

Post Reply