Unable to change Text or String to double quote

Hi, hope someone can help me out. I’m not able to use this [format]“",”[/format] command. It always Returns [format]",[/format] but I only need [format]",[/format]

This is the script I’m using:


set csvLines to read "/tmp/sample.csv"

set recs to paragraphs of csvLines

-- getting values for each record
set vals to {}
set AppleScript's text item delimiters to "','"

repeat with i from 1 to length of recs
	set end of vals to text items of (item i of recs)
end repeat

--return vals as string
set the message_text to ¬
	vals
set the message_text to replace_chars(message_text, "','", "\",")

return message_text

Hi,

Your vals is list of strings as I understand. So, to get some string (text) of this list you should get some item of this list:


set vals to {"SomeText",  "OtherText",   "\","} ---- here  "\"," is 3rd text of vals

repeat with i from 1 to count vals
	set message_text to item i of vals
end repeat
-- The result of last command --> ",

This is what I want:

I’m having a .csv file with the following entries:

name1, surname1
name2, surname2

I want to put the data to a list where the list entries are: {“name1, surname1”,“name2,surname2”}

but my problem is, that my list looks like that:
{{“name1, surname1”}, {“name2, surname2”}, {}}

So, I need to replace “}, {” to “,”

This ist the code I’m using for that:

set csvLines to read "/tmp/sample.csv"
set recs to paragraphs of csvLines

set vals to {}
set AppleScript's text item delimiters to "','"

repeat with i from 1 to length of recs
	set end of vals to text items of (item i of recs)
end repeat

return vals


set vals to paragraphs 1 thru -2 of (read "/tmp/sample.csv")

I tested using what you provided to me:


set csvLines to "name1, surname1
name2, surname2
"
set vals to paragraphs 1 thru -2 of csvLines

Wow, just one line.

Thank you so much that’s what I was looking for :slight_smile: