get nth letter of word

I’m trying to write a script to allow me to get the first, then the second then the third letter of an email address…


repeat with loopcount from "4" to (number of characters in email)
	set num11 to (nth character in email)
end repeat

Where it says nth character, I want it to get the current loopcount value (4 in the first repeat) and then get that numbered character. It works if I type first, second third fourth, but I can’t get it to some way involving a variable…

Can anyone help?

Hi,

You can get the 11th character of a string like this:

set the_address to “someone@somewhere.com
set char11 to character 11 of the_address

What are you trying to do? There might be an easier way to do something.

gl,

Here’s how to use the loop variable:

set the_address to “someone@somewhere.com
set l to length of the_address
repeat with i from 4 to l
set num11 to character i of the_address
display dialog num11
end repeat

gl,