I need to get a text from another text, the same way as I can get a string from another string by its location. What is the function to use?
line1=“Miami@LosAngeles”
put range("@", line1) into locationofatsign
put length(line1) into lengthofline1
I need to get “Miami” from “Miami@LosAngeles” so basically i need to get the first 5 letters before the @ sign. I’d like to get the letters after the @ sign too which will be “LosAngeles”
How do I get the text based on the location of another text?
The split function might work well in this case:
split line1 by "@" -- creates a list ("Miami", "LosAngeles")
put the first item of line1 into city1
put the second item of line1 into city2
put city1 -- shows "Miami"
put city2 -- shows "LosAngeles"
Search for “split” in the SenseTalk manual for more examples.
Yes, using split is probably the simplest choice in this case. Here’s a neat way to do it in one line:
put line1 split by "@" into (city1,city2)
Another common way to do this would be to treat the line as a series of text items delimited by “@” like this:
put item 1 delimited by "@" of line1 into city1
put item 2 delimited by "@" of line1 into city2
Using the offset function to find the location of the “@” and then using that to get the characters before or after it is also doable, but is a bit more work:
put the offset of "@" in line1 into locationOfAtSign
put characters 1 to locationOfAtSign-1 of line1 into city1
put characters locationOfAtSign+1`to last of line1 into city2
I went to the reference and saw the split function and knew that was what I needed, but the reference didn’t tell me where the second value goes after you split it. If you want you can update the reference manual for a better example like what you guys provided. Thanks so much for the support.
[quote=“SenseTalkDoug”]Yes, using split is probably the simplest choice in this case. Here’s a neat way to do it in one line:
put line1 split by "@" into (city1,city2)
Another common way to do this would be to treat the line as a series of text items delimited by “@” like this:
put item 1 delimited by "@" of line1 into city1
put item 2 delimited by "@" of line1 into city2
Using the offset function to find the location of the “@” and then using that to get the characters before or after it is also doable, but is a bit more work:
put the offset of "@" in line1 into locationOfAtSign
put characters 1 to locationOfAtSign-1 of line1 into city1
put characters locationOfAtSign+1`to last of line1 into city2
[/quote]
Yes this is great also. You should place this in the Reference Manual because I didn’t see an example of how you get a text by location.