thanks, i tried it with componentsSeparatedByString like this:
set ausgabe to "one:two:three:four"
set ausgabe_array to ausgabe's componentsSeparatedByString_(":")
debug_("ergebnis: " & ausgabe_array)
“debug_” is just a function that puts a string inside a textfield to debug.
i also tried a few other things like
set ausgabe_array to componentsSeparatedByString_(ausgabe, “:”)
set ausgabe_array to componentsSeparatedByString_(ausgabe, “:”) as string
set ausgabe_array to ausgabe’s componentsSeparatedByString_(“:”) as string
none of it worked though.
Any idea how this would work?
You can’t call an NSString’s method on an AS string – you need to convert it to an NSString first. Something like:
set ausgabe to "one:two:three:four"
set ausgabe to current application's NSString's stringWithString_("one:two:three:four")
set ausgabe_array to ausgabe's componentsSeparatedByString_(":")
Thanks, it did work with the test string (one:two:three…).
I wanted to separate the string at each line, so the first line is the first index, the second line is the second index, etc.
Normaly (in PHP that is for me), i’d just use a “\n” as separator. This however doens’t work in here, as the \n is translated into an new line directly in the code.
Even though the “\n” adds a new line in the code, it will work. Sometimes you need to use “\r”
Another option is to use the AppleScript keyword return.
there is also a componentsSeparatedByCharactersInSet: method of class NSString,
use it with the predefined newlineCharacterSet. It contains \r, \n and unicode U+0085.
The equivalent ObjC code is
thanks mark.
I read the article and think the “NSParagraphSeparatorCharacter” is what I’m looking for.
I tried using it as a constant like this:
set ausgabearray to ausgabe's componentsSeparatedByString_(NSParagraphSeparatorCharacter)
Didn’t work.
I also made a few other tries like
set separator to current application's NSText's NSParagraphSeparatorCharacter
set separator to current application's NSText's NSParagraphSeparatorCharacter()
none of it worked though.
(sorry for being such a noob)