Why does "-" not count as a word?

Why does this work:
set x to “4+” → “4+”
words of x → {“4”, “+”}

and this NOT work:
set x to “4-” → “4-”
words of x → {“4”}

Shouldn’t the second example result in a list containing {“4”, “-”} like the first example did with the “+” sign?

I am testing this in Smile 2.5.2 running System 10.2.3.

Thanks in Advance,
Brad Bumgarner, CTA

I’m not sure why this doesn’t work, but it doesn’t (10.3.2). However, as a workaround.

set x to “4-”
characters of x

this yields {“4”, “-”}

I thought about using characters, however, I will be encountering code such as:

“12+16-”

that needs to be coerced into:

{“12”, “+”, “16”, “-”}

EVERYTHING else works the way you would think, EXCEPT for the “-” sign. :cry: It’s really going to make for a lot of extra coding to handle this and it needs to work FAST because this code will be utilitized during input. I’d hate to have to wait a while between each input is entered.

Brad Bumgarner, CTA

Not a lot of extra coding but still more:

set x to "12+16-"
set x to my minus_cleanup(x)
return x -->{"12", "+", "16", "-"}

on snr(the_string, search_string, replace_string)
	set old_delim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to search_string
	set the_string to text items of the_string
	set AppleScript's text item delimiters to replace_string
	set the_string to the_string as string
	set AppleScript's text item delimiters to old_delim
	return the_string
end snr

on minus_cleanup(x)
	if x does not contain "-" then return words of x
	set x to my snr(x, "-", ":minus:")
	set x to words of x
	repeat with i from 1 to (count x)
		if item i of x = "minus" then set item i of x to "-"
	end repeat
	return x
end minus_cleanup

I’m sure there’s some thing to consider or ignore (punctuation, white space, etc.) to get AppleScript to treat the minus sign appropriately but I’m not sure what it is.

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Hi,

The minus sign is a hyphen which also seperates words. Here are some other things that aren’t words:

tab
line feed
carriage return
space
exclamation mark
double quote
single quote
left parenthesis
right parenthesis
comma
hyphen
period
forward slash
colon
semi colon
question mark
left square bracket
right square bracket
left curly bracket
right curly bracket

Excuse miss spellings and made up words :-). Note that parenthesis will group your math stuff. You need to take into account order of operation.

gl,

Hi,

Just trying to think about workarounds. Maybe at the beginning, yuo can change all hyphens in the text to something else.

Um, that’s the solution I provided above.

Jon

Hi Jon,

I was one track minded and saw your post after I posted. But when I posted there was an error so I didn’t think it posted. Anyway, great idea you got there.

Just drank 3 bottles of pepsi.

I’m a graphics artist. I SHOULD have thought of that! :rolleyes: Thanks for the info.

Jonn,

I will check out your code later today when I get the chance. I knew if you saw this post that you would come up with a solution. Thanks.

Brad Bumgarner, CTA

Jon,

I inserted your code and it works like a charm! Thanks. You always have such elegant solutions.

Brad Bumgarner, CTA