Applescript:摆脱空间并回归线

时间:2016-05-26 06:20:03

标签: variables text applescript

我无法摆脱ma变量中的行和空格的返回。

这是我目前的结果

  

156545690

     

446654319

     

1047473595

我希望:

  

156545690,446654319,1047473595

甚至更好

  

号码:156545690,号码:446654319,号码:1047473595

摆脱这里的行是我当前的脚本

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

1 个答案:

答案 0 :(得分:1)

在这种情况下,我建议重复循环,它会跳过空行并添加NUMBER前缀。然后text item delimiters将列表转换为字符串。

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