Hi. Well as far as I know, there are no commands which do this although it could certainly be implemented as a plugin. Until someone does that, here are some functions I've just thrown together for you to use. I've tested them but as they're new, do tell me if they cause you any problems.
function InsertInDelimiter(sInput$,sDelimiter$,sData$,nPos)
if nPos > 0 and nPos <= CountFields(sInput$,sDelimiter$) + 1
if nPos = 1
sOutput$ = sData$ + sDelimiter$ + sInput$
else
if nPos = CountFields(sInput$,sDelimiter$) + 1
sOutput$ = sInput$ + sDelimiter$ + sData$
else
nTruePos = 0
for c = 1 to nPos - 1
nTruePos = instr(sInput$,sDelimiter$,nTruePos + 1)
next c
sOutput$ = left$(sInput$,nTruePos - 1) + sDelimiter$ + sData$ + right$(sInput$,len(sInput$) - nTruePos + 1)
endif
endif
else
sOutput$ = sInput$
endif
endfunction sOutput$
function ReplaceInDelimiter(sInput$,sDelimiter$,sData$,nPos)
if nPos > 0 and nPos <= CountFields(sInput$,sDelimiter$)
if nPos = 1
nStart = 0
nEnd = instr(sInput$,sDelimiter$,nStart + 1)
else
for c = 1 to nPos - 1
nStart = instr(sInput$,sDelimiter$,nStart + 1)
next c
nEnd = instr(sInput$,sDelimiter$,nStart + 1)
endif
if nEnd = 0
nEnd = len(sInput$)
sOutput$ = left$(sInput$,nStart) + sData$ + right$(sInput$,len(sInput$) - nEnd)
else
sOutput$ = left$(sInput$,nStart) + sData$ + right$(sInput$,len(sInput$) - nEnd + 1)
endif
else
sOutput$ = sInput$
endif
endfunction sOutput$
function DeleteInDelimiter(sInput$,sDelimiter$,nPos)
if nPos > 0 and nPos <= CountFields(sInput$,sDelimiter$)
if nPos = 1
nStart = 0
nEnd = instr(sInput$,sDelimiter$,nStart + 1)
else
for c = 1 to nPos - 1
nStart = instr(sInput$,sDelimiter$,nStart + 1)
next c
nEnd = instr(sInput$,sDelimiter$,nStart + 1)
endif
if nEnd = 0
nEnd = len(sInput$)
sOutput$ = left$(sInput$,nStart - 1) + right$(sInput$,len(sInput$) - nEnd)
else
if nPos = 1
sOutput$ = left$(sInput$,nStart - 1) + right$(sInput$,len(sInput$) - nEnd)
else
sOutput$ = left$(sInput$,nStart - 1) + right$(sInput$,len(sInput$) - nEnd + 1)
endif
endif
else
sOutput$ = sInput$
endif
endfunction sOutput$
function CountFields(sInput$,sDelimiter$)
nPos = 0
nOutput = 0
while instr(sInput$,sDelimiter$,nPos + 1) > 0
nPos = instr(sInput$,sDelimiter$,nPos + 1)
inc nOutput
endwhile
inc nOutput
endfunction nOutput
I'm not promising that this is the most efficient way to do this but it seems to work. InsertInDelimiter() allows you to add an item to the list at a given position without deleting any of the existing items. You can add items at the start of the list using the index 1 and at the end by giving an index which is one higher than the number of fields in the list. ReplaceInDelimiter() will swap an item at a given position for a new item of data. DeleteInDelimiter() will delete an item of data at the given position and replace it with nothing. CountFields() will tell you how many fields there are in your list.
This code should showcase what the functions can do.
sString$ = "Tuna,Catfish,Monkfish,Cod,Bass"
print sString$
` Replace item as position two with dogfish
sString$ = ReplaceInDelimiter(sString$,",","Dogfish",2)
print sString$
` Put catfish in the third position in the list
sString$ = InsertInDelimiter(sString$,",","Catfish",3)
print sString$
` Add a new item to the end of the list
sString$ = InsertInDelimiter(sString$,",","Trout",CountFields(sString$,",") + 1)
print sString$
` Add a new item at the start of the list
sString$ = InsertInDelimiter(sString$,",","Salmon",1)
print sString$
` Delete item 6
sString$ = DeleteInDelimiter(sString$,",",6)
print sString$
` Show number in list
print "Number of items in list: " + str$(CountFields(sString$,","))
wait key
end
Hope this helps. Just say if this is not what you're looking for. Regards.