removing escape characters from string

I’m not good with text manipulation but have tried this and I am getting nowhere.

I need to convert a string to a list while removing the escape character

The string is ""0045ND","Cara Lippett","Cara Lippett_0045ND","vxxxitt@aol.com",""

and I wish to get to {“0045ND”, “Cara Lippett”, “Cara Lippett_0045ND”, “vxxxitt@aol.com”}

I cannot remove \ and establish the correct list.

Stumped of London

This solution is anything but elegant (brute force, in fact), but it is plain vanilla AppleScript:


set theString to "\"0045ND\",\"Cara  Lippett\",\"Cara  Lippett_0045ND\",\"vxxxitt@aol.com\",\"\""
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\""
set tParts to text items of theString
set AppleScript's text item delimiters to tid
set newList to {}
repeat with j from 2 to 8 by 2
	set end of newList to item j of tParts
end repeat
newList --> {"0045ND", "Cara  Lippett", "Cara  Lippett_0045ND", "vxxxitt@aol.com"}

Hi,

Those backslashes within the string would not be written out to anything as they are escape characters. However if you just return the string as you have posted here, (or set the string to a variable):

set a to "\"0045ND\",\"Cara  Lippett\",\"Cara  Lippett_0045ND\",\"vxxxitt@aol.com\",\"\"" as list

The results window will display:

{“"0045ND","Cara Lippett","Cara Lippett_0045ND","vxxxitt@aol.com",""”}

The results window shows the escape characters too!

But if you tell Applescript to display this variable with:

set a to "\"0045ND\",\"Cara  Lippett\",\"Cara  Lippett_0045ND\",\"vxxxitt@aol.com\",\"\"" as list
display dialog a

Or even write the variable to a text file with

set a to "\"0045ND\",\"Cara  Lippett\",\"Cara  Lippett_0045ND\",\"vxxxitt@aol.com\",\"\"" as list
do shell script "echo " & a & " >~/Desktop/test.txt"

You will see that those escape characters are not there!!

I’m not sure if this is what you are experiencing, or are you reading the original string from an external file??

EDIT:
I see Adam has posted a solution just before me, but this is worth bearing in mind! (I think!?)

Another “brute force” method would be this:

set theString to "\"0045ND\",\"Cara  Lippett\",\"Cara  Lippett_0045ND\",\"vxxxitt@aol.com\",\"\""
set newList to items 1 thru -2 of (run script "{" & theString & "}")

But, like Adam’s script, it’s aimed at getting that particular list from that particular string, which could be done manually. A more general script isn’t possible without knowing how your string’s derived.

Neat, Nigel;

I tried a run script construction as well, but forgot to stick in the end quotes you have in:

to form the required list structure. Senior moment.