Kevin
Kevin

Reputation: 1106

Applescript : Get rid of space and return to line

I can't get rid of the return to line and space in ma variable.

Here is my result at the moment

156545690

446654319

1047473595

and I would like to have :

156545690, 446654319, 1047473595

or even beter

NUMBER : 156545690, NUMBER : 446654319, NUMBER : 1047473595

for get rid of the line here is my current script

set refnumberList to my getInputByClass2("sortable datanumber", 1)

to getInputByClass2(theClass) 
    tell application "Safari"
        set r to do JavaScript "var outPut=[]; var arr=document.getElementsByClassName('" & theClass & "');for (var i in arr) {outPut.push(arr[i].innerHTML)};outPut;" in document 1
    end tell
    return strings of r 
    end getInputByClass2


set goodresult to items 2 thru -1 of refnumberList as string

set x to goodresult
set AppleScript's text item delimiters to ""
set y to (words of x)
set AppleScript's text item delimiters to ""
get y as string

set the clipboard to items 2 thru -1 of refnumberList as string

Upvotes: 0

Views: 76

Answers (1)

vadian
vadian

Reputation: 285180

In this case I'd recommend a repeat loop, it skips the empty lines and adds the NUMBER prefix. Then text item delimiters converts the list to a string.

set theText to "156545690

446654319

1047473595
"

set theResult to {}
repeat with aLine in (get paragraphs of theText)
    if length of aLine > 0 then
        set end of theResult to "NUMBER: " & contents of aLine
    end if
end repeat
set {TID, text item delimiters} to {text item delimiters, ", "}
set theResult to theResult as text
set text item delimiters to TID
theResult

Upvotes: 1

Related Questions