You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Anyhow, I think PB support would prefer an official request made at support at powerbasic dot com.
So better to send them a mail in any case regardless what will be the results of this poll.
Well, you should send in the NSF; it sounds pretty usable.
But this is the kind of situation where I just write my own function make sure it's includeable so I can re-use it. (Or if I'm in a good mood, post a demo here).
What comes to mind here is a header ...
Code:
FUNCTION JoinPartOfArray (s() AS STRING, delim AS STRING, _
OPTIONAL startsub as LONG, OPTIONAL endsub AS LONG) AS STRING
code here
END FUNCTION
If endSub not passed use UBOUND.; if startsub not passed use LBOUND.
CALLS:
Code:
S$ = JoinPartOfArray (foo(),"*", 5) ' from subscript 5 to end using *
S$ = JoinPartOfArray (foo(), ",", 6, 32) ' from subs 5 to 32 only using comma
S$ = JoinPartOfArray (foo(), "|") ' whole array (= JOIN$) using pipe
#COMPILE EXE
#DIM ALL
'FUNCTION joPar() joins dynamic string arrays or parts of them
FUNCTION joPar(arr() AS STRING, a AS LONG, b AS LONG, delim AS STRING) AS STRING
LOCAL x, y, lod AS LONG
LOCAL jStr AS STRING
x = STRPTR(arr(a))
y = STRPTR(arr(b))
IF (x AND y) = 0 THEN ? "Error, invalid array type or array element": EXIT FUNCTION
lod = LEN(delim)
jStr = SPACE$(y - x + LEN(arr(b)) + (b - a + 1) * lod) 'make big enough string to hold join
x = 1
FOR y = a TO b
MID$(jStr, x) = arr(y) 'write an arr element
x = x + LEN(arr(y))
MID$(jStr, x) = delim 'join it
x = x + lod
NEXT
FUNCTION = LEFT$(jStr, x - (lod + 1)) 'trim excess
END FUNCTION
'FUNCTION joParF() joins fixed string arrays or parts of them. String len needs to be specified each time used.
'In this example it is STRING * 100
FUNCTION joParF(arr() AS STRING * 100, a AS LONG, b AS LONG, delim AS STRING) AS STRING
LOCAL x, y, lod AS LONG
LOCAL jStr AS STRING
x = VARPTR(arr(a))
y = VARPTR(arr(b))
IF (x AND y) = 0 THEN ? "Error, invalid array type or array element": EXIT FUNCTION
lod = LEN(delim)
jStr = SPACE$(y - x + LEN(arr(b)) + (b - a + 1) * lod)
x = 1
FOR y = a TO b
MID$(jStr, x) = arr(y)
x = x + LEN(arr(y)) '<< can replace w/ x = x + 100 (whatever fixed str len is) for efficiency
MID$(jStr, x) = delim
x = x + lod
NEXT
FUNCTION = LEFT$(jStr, x - (lod + 1))
END FUNCTION
'join parts of arrays using functions joPar & joParF
FUNCTION PBMAIN () AS LONG
LOCAL a AS STRING, ii AS LONG, ip AS LONG PTR, t AS SINGLE
DIM strArr(5000) AS STRING
DIM strArr2(5000) AS STRING * 100
OPEN "c:\joPar1dTest.txt" FOR OUTPUT AS #1
FOR ii = 0 TO 5000
strArr(ii) = REPEAT$(ii, "ooo")
strArr2(ii) = STR$(ii) & "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
NEXT
t = TIMER
PRINT #1, joPar (strArr(), 751, 1250, $CRLF)
PRINT #1, joParF(strArr2(), 1954, 2004, $CRLF)
? "k" & STR$(TIMER - t)
END FUNCTION
Perhaps this is the reason that it is left the way it is. Each of us having a slightly different concept of how to go about it. I would have used a macro.
I'm not sure that any of us would be more 'right' in how we go about it.
Rod
PS
Poll could have used "Don't know" and/or "Don't care" as additional option(s).
Last edited by Rodney Hicks; 18 Jul 2008, 09:02 AM.
Reason: add postscript
Rod
In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment