Page 1 of 1
I want to match a chunk exactly with replace
Posted: Sat Aug 19, 2017 3:11 pm
by Da_Elf
I thought wholematches would work but it doesnt. I only want to remove "1" which shows up twice
Code: Select all
on mouseUp
put "22,34,12,1,121,1" into list
set the wholematches to true
replace "1" with "" in list
replace ",," with "," in list
if the last char of list is "," then delete the last char of list
answer list
end mouseUp
Re: I want to match a chunk exactly with replace
Posted: Sat Aug 19, 2017 3:26 pm
by [-hh]
You could try this.
Code: Select all
on mouseUp
filter items of "22,34,12,1,121,1" without "1" into lst
answer lst
end mouseUp
Re: I want to match a chunk exactly with replace
Posted: Sat Aug 19, 2017 3:29 pm
by Klaus
Hi Da_Elf,
I might repeat myself, but the dictionary is your friend!
About "Wholematches":
...
Specifies whether the lineOffset, wordOffset, and itemOffset functions search only for entire lines, words, or items.
...
No mention of "replace".
Do this:
Code: Select all
on mouseUp
put "22,34,12,1,121,1" into tList
set the wholematches to true
put empty into tNewList
repeat for each item tItem in tList
if itemoffset(tItem,tNewList) = 0 then
put tItem & "," after tNewList
end if
end repeat
delete char -1 of tNewList
answer tNewList
end mouseUp
In LC it is often faster to create a new list than modify an existing list!
Best
Klaus
Re: I want to match a chunk exactly with replace
Posted: Sat Aug 19, 2017 6:31 pm
by Da_Elf
both great answers. thanks guys.