How do I find newline characters?

I have a string that consists of multiple lines. What is the substring for ‘offset’ to find the newline characters (‘\n’ does not work) so I can extract each line and process it? TIA.

Let me reframe this questions as there is likely a better way to do what I want then what I have in mind. I have string which consists of a series of ordered pairs seperated by newline characters. I would like to access these pairs as seperate items. That is, I have:

The string is:

“thing1 thing2
thing3 thing4
thing5 thing6”

What I want is:

set things to {thing1 thing2 thing3 thing4 thing5 thing6}

TIA.

Try this:

set test to "thing1 thing2
thing3 thing4
thing5 thing6"

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ASCII character 10 -- Line feed. Use 13 for carriage return.
set pairs to every text item of test
set AppleScript's text item delimiters to ASTID

return pairs

Thanks. I don’t know how I would have ever figured that out from my documentation. However, it is only close, very close but this is not horseshoes or handgrenades.

set test to "thing1 thing2
thing3 thing4
thing5 thing6"

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ASCII character 10 -- Line feed. Use 13 for carriage return.
set pairs to every text item of test
set AppleScript's text item delimiters to ASTID
display dialog number of items in pairs

The dialog displays the number 3. It should be 6. I am guessing that it treated each line as a single item rather then each ‘thing’ as an item. Probably my fault for not being more clear about what I wanted. I tried a couple of modifications to use spaces as delimiters but I obviously did not hit the right syntax.

I read “pairs” as meaning you wanted them together.

Try this:

set test to "thing1 thing2
thing3 thing4
thing5 thing6"

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ASCII character 10
set things to every text item of test
set AppleScript's text item delimiters to " "
set things to every text item of (things as text)
set AppleScript's text item delimiters to ASTID

return things

As covered many times before, line endings can be any of several delimiters but AppleScript makes this easy for you by allowing you to delimit text by paragraph no matter which line ending is used (Mac, DOS, or Unix). So, this is what I would use:

set the_content to "thing1 thing2
thing3 thing4
thing5 thing6"

set the_pairs to the_content's paragraphs
repeat with i from 1 to (count the_pairs)
	set item i of the_pairs to my string_to_list(item i of the_pairs, " ")
end repeat
return the_pairs
-->{{"thing1", "thing2"}, {"thing3", "thing4"}, {"thing5", "thing6"}}

on string_to_list(the_string, the_delim)
	tell (a reference to my text item delimiters)
		set {old_tid, contents} to {contents, the_delim}
		set {the_string, contents} to {the_string's text items, old_tid}
	end tell
	return the_string
end string_to_list

Or, if you really want individual items instead of pairs:

set the_content to "thing1 thing2
thing3 thing4
thing5 thing6"

set the_content to my list_to_string(the_content's paragraphs, " ")
set the_content to my string_to_list(the_content, " ")
return the_content
-->{"thing1", "thing2", "thing3", "thing4", "thing5", "thing6"}

on string_to_list(the_string, the_delim)
	tell (a reference to my text item delimiters)
		set {old_tid, contents} to {contents, the_delim}
		set {the_string, contents} to {the_string's text items, old_tid}
	end tell
	return the_string
end string_to_list

on list_to_string(the_list, the_delim)
	tell (a reference to my text item delimiters)
		set {old_tid, contents} to {contents, the_delim}
		set {the_list, contents} to {the_list as Unicode text, old_tid}
	end tell
	return the_list
end list_to_string

Jon

Got it. Thanks. Now on to the next layer of the onion, posted as a new topic.