I want to add first item of list convert to #resultat and add begining of 2nd and 3rd item, and convert ## Disccusion to #Disccusion tag and add begining of 5 th item, and convert ## Donec to #Donec and add begining of 7 and 8. items.
Could you help me? Thanks
set this_list to {"## Resultat ", "Quisq1.ue ac t", "mine", "## Disccusion", "Proin1. eu dapibus elit.", "## Donec", "Jagnon ", "dinen"}
set thelenght to length of this_list
set outlist to ""
repeat with i from 1 to number of items in this_list
set currentText to item i of this_list
if currentText contains "## " then
set x to currentText
else
-- display dialog "no"
end if
set outlist to outlist & x as list
end repeat
set numberlist to ""
repeat with i from 1 to number of items in outlist
set firstn to item i of outlist
set pp to list_position(firstn, this_list)
set ntag to ("#" & characters 4 through -1 of firstn as string) & " "
set zz to thelenght - pp
set currentCount to -1
repeat zz times
set currentCount to currentCount + 1
set yy to zz - currentCount
--display dialog "Count is now " & yy & "."
set item1 to ntag & item (pp + yy) of this_list
end repeat
set numberlist to numberlist & item1 as list
end repeat
Thank you very much. It is awesome. But it merged (2 nd and 3rd item ) and (7 -8 item) . I want to add as separated item and whole content of item. Like below.
{“#Resultat Quisq1.ue ac t”,“#Resultat mine”, “#Disccusion Proin1. eu dapibus elit.”, "#Donec Jagnon, “#Donec dinen”}
set this_list to {"## Resultat ", "Quisq1.ue ac t ", "mine", "## Disccusion ", "Proin1. eu dapibus elit.", "## Donec ", "Jagnon ", "dinen"}
set newList to {}
repeat with currentItem in this_list
if currentItem begins with "## " then
set startItem to currentItem -- remember item with "## "
else
set end of newList to "#" & (text 4 thru -1 of startItem) & currentItem
end if
end repeat
return newList
set this_list to {"## Resultat ", "Quisq1.ue ac t ", "mine", "## Disccusion ", "Proin1. eu dapibus elit.", "## Donec ", "Jagnon ", "dinen"}
set newList to {}
repeat with currentItem in this_list
if currentItem begins with "## " then
set startItem to currentItem -- remember item with "## "
set end of newList to items of currentItem as string
else
set end of newList to "#" & (text 4 thru -1 of startItem) & currentItem
end if
end repeat
return newList
No need getting items of currentItem, then coercing to the string, because it is reference to single item in the list. You need contents of currentItem instead.
set this_list to {"## Resultat ", "Quisq1.ue ac t ", "mine", "## Disccusion ", "Proin1. eu dapibus elit.", "## Donec ", "Jagnon ", "dinen"}
set newList to {}
repeat with currentItem in this_list
if currentItem begins with "## " then
set startItem to currentItem -- remember item with "## "
set end of newList to contents of currentItem
else
set end of newList to "#" & (text 4 thru -1 of startItem) & currentItem
end if
end repeat
return newList
Little tutorial: every reference of items of the list is like this: item 1 , item 2 and so on. They are addresses (relative to the address of list itself) in the RAM. Contents is what is stored at this reference (address), for example: “hello”, 3.14 and so on.
drsn. I’m glad you have a script with KniazidisR’s help that does what you want. Before posting my suggestion, I read your original post perhaps 10 times and simply could not determine precisely what it was you wanted to accomplish. I guess in circumstances like that it’s best not to respond. Anyways, my script is of no help, so I’ve deleted it.
I am sorry, My English is not so good. Because of that maybe I am not using correct sentence or describe very well. But I thanks to everybody who helps to each other. I am sorry again if I say something wrong. Great thanks again.