Posts: 39
Threads: 14
Joined: Nov 2011
Good morning QM Forum,
I've been trying to accomplish this task without asking, but I'm stuck at the last bit of information that I need. I'm working on a collaborative macro that displays online users in the main dialog box. It gets this information from a web page using InitGetFile. I've simulated that process with the accountList str. When a user signs out of the software I want to remove them from the list. If the account isn't the first in the list the example works perfectly, but if the account is the first item in the list it will leave the top spot empty instead of replacing it.
I know that I can find the line of the username with numlines and can check if line = 0, but I'm not sure how to remove the empty item at the top.
Macro
Example String Replacement
;; simulates the info received from webpage
str accountList = "account1[]account2[]account3[]account4[]account5"
str getAccount = "account1"
accountList.replacerx(getAccount "")
accountList.findreplace("[][]" "[]" 8)
out accountList
Posts: 39
Threads: 14
Joined: Nov 2011
Currently working on implementing the str.RemoveLineN member function listed here:
http://www.quickmacros.com/forum/showthr...mpty+lines
I was able to figure out how to remove the space if it's the first item, but now working out the kinks to remove the space if it's the last item.
Posts: 1,338
Threads: 61
Joined: Jul 2006
this should work for you
Macro
[b]Example String Replacement[/b]
;;;simulates the info received from webpage
str accountList = "account1[]account2[]account3[]account4[]account5"
str getAccount = "account1"
getAccount +"[]"
accountList.replacerx(getAccount "" 8)
out accountList
Posts: 39
Threads: 14
Joined: Nov 2011
Thank you Kevin! This works for my initial problem and the follow up post.
Posts: 1,338
Threads: 61
Joined: Jul 2006
06-26-2018, 04:56 PM
(This post was last modified: 06-26-2018, 05:03 PM by Kevin.)
after looking further this is a better way to go converts to array finds item and removes it then converts back to multiline string
Macro
Example String Replacement
;;;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
Posts: 39
Threads: 14
Joined: Nov 2011
I've incorporated your other post and everything works great. An array will definitely help once the user list gets larger. I will definitely incorporate this into everything. Thank you sir!
Posts: 1,338
Threads: 61
Joined: Jul 2006
06-26-2018, 06:10 PM
(This post was last modified: 06-26-2018, 06:13 PM by Kevin.)
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
;;;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
;;;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
;;;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
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
Posts: 39
Threads: 14
Joined: Nov 2011
I'm glad you pointed that out because I did not notice it at first since the user I was testing was never in the situation of being last unless if was the only account. In that situation it defaults to "None" upon close. I will add these updates. Thank you for the dual examples!