Page 1 of 1

String position

Posted: Tue Aug 17, 2010 7:02 pm
by p4tr1ck
How would I get a char at a given position in a string?
For example, 0 in string "Hello" would be "H".
Thanks.

Re: String position

Posted: Tue Aug 17, 2010 7:35 pm
by bn
Patrick,

Rev starts counting characters (chars) at 1.
To get at a char just say "put char x of myVarible/myField into myOtherVariable/myOtherField

Code: Select all

on mouseUp
   put "Hello" into tData
   repeat with i = 1 to the length of tData
      put "char " & i & ":" &&  char i of tData
      wait 1 second
   end repeat
   put empty
end mouseUp
this puts the chars of Hello one by one into the message box
regards
Bernd

Re: String position

Posted: Tue Aug 17, 2010 7:43 pm
by p4tr1ck
Thanks for the help :)

Re: String position

Posted: Mon Feb 28, 2011 8:16 pm
by stevewhyte
Hi,

I'm trying to find the position of a character within a string.

Here is the set up:

put "abcdefghijklmnopqrstuvwxyz" into alpha

If I wanted to find the position of letter "c", how would I carry this out?

The answer produced by the program should be 3.

Regards,

Steven

Re: String position

Posted: Mon Feb 28, 2011 8:36 pm
by Klaus
Hi Steven

...
put "abcdefghijklmnopqrstuvwxyz" into alpha
answer offset("c",alpha)
...

Best

Klaus

Re: String position

Posted: Mon Feb 28, 2011 8:40 pm
by stevewhyte
You're a legend! Thank you so much!