Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find & Remove String From List
#7
I apologize when i posted 1st time i was half asleep and the initial post wont work for all circumstances

if the user  is the last line of the string this won't work.
Macro Example String Replacement
Code:
Copy      Help
;;;simulates the info received from webpage
str accountList = "account1[]account2[]account3[]account4[]account5"
str getAccount  = "account5"
getAccount +"[]"
accountList.replacerx(getAccount "" 8)
out accountList

so use either this

Macro Example String Replacement1
Code:
Copy      Help
;;;simulates the info received from webpage
str accountList = "account1[]account2[]account3[]account4[]account5"
str getAccount  = "account5"
ARRAY(str) arr
int i nt
nt = tok(accountList arr)
for(i 0 nt)
,if arr[i]= getAccount
,,int rs=i
arr.remove(rs)    
accountList=arr
accountList.trim
out accountList

or use this
Macro Example String Replacement2
Code:
Copy      Help
;;;simulates the info received from webpage
str accountList = "account1[]account2[]account3[]account4[]account5"
str getAccount  = "account5"
str s
int x
foreach s accountList
,if getAccount = s
,,accountList.RemoveLineN(x)
,x+1
accountList.trim
out accountList

Example String Replacement2 needs the function below

Member function str.RemoveLineN
Code:
Copy      Help
function# lineindex [nlines]

;Removes specified line(s).
;Returns index of first character of lineindex-th line, or -1 if lineindex is too big.

;lineindex - zero-based line index.
;nlines - number of lines to remove. Default or 0: 1 line.

;EXAMPLE
;str s="zero[]one[]two"
;s.RemoveLineN(1)
;out s


if(nlines<1) nlines=1
int i=findl(this lineindex)
if(i>=0) this.remove(i findl(this+i nlines))
ret i


Messages In This Thread
Find & Remove String From List - by BJ - 06-26-2018, 03:01 PM
RE: Find & Remove String From List - by BJ - 06-26-2018, 04:20 PM
RE: Find & Remove String From List - by Kevin - 06-26-2018, 04:21 PM
RE: Find & Remove String From List - by BJ - 06-26-2018, 04:22 PM
RE: Find & Remove String From List - by Kevin - 06-26-2018, 04:56 PM
RE: Find & Remove String From List - by BJ - 06-26-2018, 05:18 PM
RE: Find & Remove String From List - by Kevin - 06-26-2018, 06:10 PM
RE: Find & Remove String From List - by BJ - 06-26-2018, 06:58 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)