String position
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
String position
How would I get a char at a given position in a string?
For example, 0 in string "Hello" would be "H".
Thanks.
For example, 0 in string "Hello" would be "H".
Thanks.
Re: String position
Patrick,
Rev starts counting characters (chars) at 1.
To get at a char just say "put char x of myVarible/myField into myOtherVariable/myOtherFieldthis puts the chars of Hello one by one into the message box
regards
Bernd
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
regards
Bernd
-
- Posts: 25
- Joined: Mon Oct 18, 2010 6:32 pm
Re: String position
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
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
Hi Steven
...
put "abcdefghijklmnopqrstuvwxyz" into alpha
answer offset("c",alpha)
...
Best
Klaus
...
put "abcdefghijklmnopqrstuvwxyz" into alpha
answer offset("c",alpha)
...
Best
Klaus
-
- Posts: 25
- Joined: Mon Oct 18, 2010 6:32 pm
Re: String position
You're a legend! Thank you so much!