April 18, 2024, 10:13:27 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Printer Names

Started by Brian, April 13, 2021, 12:09:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

Help! I have a string of printer names, separated by a semi-colon. How can I split the string up to put the printer names in a listbox with ADDSTRING?

Brian

billhsln

I would think that you could split them up the same way you would do either a tab delimited or a comma delimited file.

Send me a sample.

Bill
When all else fails, get a bigger hammer.

ckoehn

Here is what I use to use.  I'm sure it can be improved.

SUB Split(STRING txt,STRING ch,string words[]),INT  'number of entries in the array
        'Split ( text to split, chars to split at, array to store entries)
INT i,cnt=0
string item=""

FOR i=1 to LEN(txt)
IF INSTR(ch,MID$(txt,i,1))>0 and item<>"" and cnt<(SIZEOF(words))
words[cnt]=item
cnt++
item=""
ELSE
item+=MID$(txt,i,1)
ENDIF
NEXT i

IF item<>""
words[cnt]=item
ELSE
cnt--
ENDIF

RETURN cnt
ENDSUB

Later,
Clint

billhsln

Here is another quick way to split a string:

i = -1
j = InStr(plist$,";")
do
  if j > 0
    i++
    word[i] = mid$(plist$,1,j-1)
    plist$ = mid$(plist$,j+1)
    j = InStr(plist$,";")
  endif
until j = 0
i++
word[i] = plist$

Bill
When all else fails, get a bigger hammer.

ckoehn

I have used that method too Bill.  It works really fast when splitting for just one char like a comma or semi comma like Brian was probably needing.  I would recommend it when having to split a strings needing only one char to split it.

The one I posted can split with a string of different chars, like this: item_cnt = Split("item1,item2;item3.item4", ",;.", words[]) would split into words[0] = "item1", words[1] = "item2", words[2] = "item3", words[3] = "item4".

Isn't programming fun.

Later,
Clint