How do delete the first word in a string?

My info reads in this format:
A11 D#m
B9 G
A2 G#

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

Thanks

try this:

set my_info to words 2 thru end of the_info as text

-N

Using text item delimiters you could also do

set text item delimiters to " "
set my_info to text item 2 of the_info

Though good form would also dictate you set them back when you are done

Why would you want to use TID’s ?

-N

Why would you want to use words? :wink:

Consider this:

words 2 thru end of "A11 D#m" -- not the desired result
--> {"D", "#", "m"}

What DJWaldo is saying is that words doesn’t work for him:

word 2 of "A11 D#m" -- not the desired result
--> "D"

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:)

-N

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"

The ‘rest’ option of a list do item 2 to end
So simple 2 lines

set text item delimiters to " "
set MyResult to rest of text items of "A11 D#m Test" as string

result
D#m Test

Bevan www.applescript.co.nz

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.

Well that’s it, no more sleeping for me. I show up late for the fun stuff when I do :smiley:

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.

Thanks Guys!
This Worked for me.

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.
:stuck_out_tongue:

betitdidn’t :wink:

"D#m Test" is not equal to "D#mTest"
--> true

No It works really! I only need 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

Thanks again!