Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
put "the quick brown fox" into myVariable
repeat for each character dummy in myVariable
--get the position of dummy in the string myVariable here
end repeat
...
put 0 into tCount
put empty into tBuff
put "the quick brown fox" into myVariable
repeat for each character dummy in myVariable
add 1 to tCount
put dummy & "," & tCount & cr after tBuff
--get the position of dummy in the string myVariable here
end repeat
delete char -1 of tBuff
put tBuff
...
Jean-Marc has offered one way. Here are two more. On a new card make a button and a field, and put all of "the quick brown...." in the field. Now put this in the button script:
on mouseUp
get fld 1
put 0 into charNum
repeat the number of chars of it
put offset ("e",it,charNum)into foundNum
add foundNum to charNum
if foundNum = 0 then
answer accum
exit to top
end if
put charNum & comma after accum
end repeat
end mouseUp
on mouseUp
get fld 1
repeat with y = 1 to the number of chars of it
if char y of it = "e" then put y & comma after accum
end repeat
answer accum
end mouseUp
This seems clunkier, because it goes through each char one by one.
Thanks very much for taking the time! I think, I will play around with your solutions. It's a bit tricky, because I want to use some nested loops, so I hope not to get lost in the code
Do you know how to place breakpoints in a script? If so, try them with all three offerings, and watch the values of the several variables step by step. This will not take long, and you can see what is going on.
please excuse me for not being able to express myself so good in English
I know how to use breakpoints, yes. I have to iterate through some fields with text or values. The current position of the respective loop does matter. So it's not for practice Would be nice, if this was built-in natively into LiveCode, with a 2nd parameter or so, like "repeat for each item dummy,[loop pos] in field..." I think in some situations, this could be useful.
JoeE. wrote: Wed Jul 06, 2022 2:00 pm
I have to iterate through some fields with text or values. The current position of the respective loop does matter. So it's not for practice Would be nice, if this was built-in natively into LiveCode, with a 2nd parameter or so, like "repeat for each item dummy,[loop pos] in field..." I think in some situations, this could be useful.
If you could show us a sample of the input data and an example of what you'd like the output to look like, we can help you get from one to the other easily.
Richard Gaskin LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
If you could show us a sample of the input data and an example of what you'd like the output to look like, we can help you get from one to the other easily.
put "Quick Brown Aardvark" into rawText
replace space with "" in rawText -- do not count spaces
repeat with y = 1 to the number of chars in rawText
put "Position" && y & comma && char y of rawText & return after accum
end repeat
answer accum