Stripping tabs and returns from text in a database field

I routinely export Extensis Portfolio catalog custom field values into tab delimited text files and sometimes encounter a problem when importing these files back in to a Portfolio catalog. Portfolio exports in tab delimited format so I think the problem is that tabs or new lines have slipped in to the contents of the Portfolio fields I an exporting. If while importing a tab delimited text file Portfolio encounters a tab or new line which is not at the end of a field or record, the data gets garbled. So I am stripping out the offensive characters with the snippet below.

Can I just use “tab” (as below) to strip out tabs or do I need to use “\t”? How would I represent a new line? How could I specify any character without using a literal?

Thanks for any insights.

--set text2 to my replace_chars("this is a test", " ", "-")

tell application "Portfolio"
	activate
	set workDoc to document 1
	set workGallery to a reference to gallery "all items" of workDoc
	tell workGallery
		repeat with i from 1 to count of records
			tell record i
				set value of field "Comment" to my replace_chars(value of field "Comment", tab, "")
			end tell
		end repeat
	end tell
end tell
beep 5




on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to ""
	return this_text
end replace_chars

Hi unscripted,

From the AppleScriptLanguageGuide:

Table 6-2 White space constants
Constant Value
space " "
tab “\t”
return “\r”
linefeed “\n”

You can use both. Constants out of quotes. Values embedded, but they’ll be changed when the script is compiled. You can also use the ascii values instead of the constants.

Ex.


{id of linefeed, id of return, "The rain" & character id 13 & "in Spain"}

I learned this from Stefan.

gl,

Thanks! Stefan recently helped me as well. Didn’t remember if there are cases where you need to use one or the other. Being able to get and use the character id is handy. It also helps to keep in mind that there are not many characters that need to be escaped.

Yep, perhaps if you’re sending a string that you want the actual character in then you’d slash the slash:

“\n”

You might do this when you ‘do shell scriot’ and send something to the unix.

gl,