Multiple Unicode character displayed on the fly

I am working on a utility for InDesign CS. This utility will allow the user to automate multiple search/replace commands. The purpose being to clean up supplied text files (removing multipe spaces, multiple returns, etc.). I would like to display a small black triangle as an indication of a space character. Lucida Grande has such a character and since that’s what I’m using in my text boxes I have defined a variable, SpaceChar with the appropriate Unicode information. The handler below works fine IF the first character input is a space. It doesn’t work other than that. :rolleyes:

How can I have a space character replaced anywhere in the text, on the fly?

property SpaceChar : «data utxt25b4»

on keyboard up theObject event theEvent -- called by text fields SearchText and ReplaceText
	if characters of theEvent = " " then
		set theContents to the content of theObject
		if length of theContents > 1 then
			set theContents to characters 1 thru -2 of theContents & SpaceChar as text
		else
			set theContents to SpaceChar
		end if
		set the content of theObject to theContents
	end if
end keyboard up

Thanks in advance,
Brad Bumgarner, CTA

Well that line’s an invitation for AS to screw things up. Aside from being an evil, unsafe way to get substrings, the coercion at the end will turn everything into a string, not Unicode text as you want. Use:

set theContents to text 1 thru -2 of theContents & SpaceChar

Thanks hhas,

I had no idea that I was writing “evil” code. :lol: I shall do my best to mend my evil ways and avoid the “dark side” in the future.

btw, the change works like a charm!

Thanks again,
Brad Bumgarner, CTA

OK, I have another question relating to this issue.

After changing my code, the triangles are appearing in the text fields and in the data cells of my table (using a data source). However, when I retrieve this data (either from the text field or the data source) I get question marks where the triangles should be. At this point I can’t distinguish a “real” question mark from a “space” question mark. Since everything is displaying correctly I know there has to be a way to retrieve the data with the triangles intact (or at least so they can be identified correctly).

Thanks again,
Brad Bumgarner, CTA