Numeric string into pairs

I have a string, eg: 12345678
I want to break the string into pairs, eg: 12, 34, 56, 78

Is the only way to do this to count two letters, extract them, count next two letters, extract them or is there a more streamlined way to do this?

What do you mean by streamlined?

set thevar to "123456789" as string
set thelist to {} as list
repeat
	set end of thelist to {character 1 of thevar as integer, character 2 of thevar as integer}
	log thelist
	if ((count thevar) < 2) then exit repeat
	set thevar to (text items 3 thru end of thevar as string)
	if ((count thevar) < 2) then
		set end of thelist to {thevar as integer}
		exit repeat
	end if
end repeat
thelist

Hi

I’m not sure if there’s a better way of doing this, probably!
Manipulating numbers in applescript is not a strong point of mine, however this seems to do the trick.

set j to {}
set t to "12345678"
repeat with i from 2 to count t by 2
	copy ((item i of t) - 1) & i as string to end of j
end repeat
j -->{"12", "34", "56", "78"}

Dylan i get this {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9}} as a result of your script.

Hey thats beautiful. Perfect.

Thanks!

Hi, pidge.

The odd-numbered characters of your result are derived from the even-numbered characters of the input and the even-numbered characters from the value of ‘i’! Here’s what you meant:

set t to "12345678"

set j to {}
repeat with i from 1 to count t by 2
	set end of j to text i thru (i + 1) of t
end repeat
j -->{"12", "34", "56", "78"}

Yes Nige thats exactly what i meant!
manipulating numbers in applescript isn’t a strength of mine, i over thinked it abit really.

Thanks for pointing that out.

I need more practice.
:expressionless: