How to Parse a Text Variable One Character at Time?

How do I implement this simple loop in Keyboard Maestro? I have been trying for hours and can't figure it out. I am new to Keyboard Maestro and yes I searched Google and this forum many times.

Thanks in advance for any assistance.

{
str = "12.345"
for (i = 1 to strlen(str)) {
myChar = stri[i]
...
}
}

One common way I've seen on a few posts looks this:

The macro sets the variable to a string, I used the same one you provided as an example. Next you loop through a collection that is created by regular expression. The expression uses a period which finds every character. The character is placed into local_char where actions can be taken on it. For this example, I show a notification and set a delay before the next character is shown.

3 Likes

That worked. Thanks for helping a noob.

As well as @TorreyB's method, you can manage the counting yourself and use KM's "Substring" action:

Character Test.kmmacros (2.8 KB)

Just in case you wanted to extract every third letter or something!

2 Likes