I only need the info from the second word, but the # sign is sometimes included in my info, so whenever the “#” is found a blank space is created then the “#” is erased. I need the “#” to stay there. I only need to read the second word. So ideally I am tryig to eliminate the first word from my string. How do I do that?
I wish this would work:
set my_info to the_info without word 1
or
set my_info to word 2 of the_info and treat # as a letter not a space
Actually “words” does work as I specified if you coerce result to text…however a closer look shows vulnerability if a “word character” (or whatever they’re technically called) is used in the FIRST word.
So a specified TID (as you noted) will be much better:)
Depends on the contents of the list. Consider this:
words 2 thru end of "A11 D#m Test" as text
--> "D#mTest"
Note the missing space in the result.
Even if that is the result you’re looking for, you’re depending on the TIDs being a certain value when you coerce the list to text (an empty string); If you set the TIDs to ensure the proper result, you’ll end up with something like this (I’ll avoid specifying string/text vs. Unicode text while I’m at it):
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set test to "" & (words 2 thru -1 of "A11 D#m Test")
set AppleScript's text item delimiters to ASTID
test
--> "D#mTest"
At this point, you’re not too far from something like this:
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set test to text items 2 thru -1 of "A11 D#M Test"
set AppleScript's text item delimiters to ""
set test to "" & test
set AppleScript's text item delimiters to ASTID
test
--> "D#mTest"
It’s not clear from the original post if the object of the exercise is to get just the second “word” or everything in the text except the first word. For the latter, the best way would be:
set the_info to "A11 D#m
B9 G
A2 G#"
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set my_info to text from text item 2 to -1 of the_info
set AppleScript's text item delimiters to astid
my_info
If only the second word’s required, ‘text item 2’ will contain the second word, the first line ending, and the third word. In order to avoid making assumptions about where the line ending is in relation to the word, something like this would do:
set the_info to "A11 D#m
B9 G
A2 G#"
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
tell the_info's paragraphs to set single_line to item 1 & space & rest
set my_info to text item 2 of single_line
set AppleScript's text item delimiters to astid
my_info
Both of the above return my_info with the same class as the_info.
Hard to beat Nigel or Stefan to the punch, James - at 10:30 AM in Nova Scotia, it’s 8:30 AM in Chicago, but it’s 2:30 PM where Nigel is and 3:30 PM at Stefan’s location.
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set test to "" & (words 2 thru -1 of "A11 D#m Test")
set AppleScript's text item delimiters to ASTID
Ultimately I only needed to get rid of the first word.
You removed the space in your test string as well. Maybe it doesn’t affect your actual usage, but I suspect others who find this thread would expect some code that removes only the first word.
Thats funny cause I just copied from the post and mysteriously the space in between the “” disapeared…Hmmm
Forum ghosts!!! Here is what worked:
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set my_info to text from text item 2 to -1 of the_info
set AppleScript's text item delimiters to astid