May 09, 2024, 08:07:16 PM

News:

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


Wish List for IWBasic 2.0

Started by Logman, March 18, 2011, 09:55:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Logman

March 18, 2011, 09:55:37 AM Last Edit: March 18, 2011, 10:05:09 AM by Logman
Larry, Sapero:

There is one string function I'd really like to see added to IWBasic in the next upgrade that would make string manipulation on par with several other languages. It would also add tremendous power to IWBasic.



PARSE$/WPARSE$

Syntax
INT = PARSE$(str as STRING, delimeters as STRING, strArray as STRING)
INT = WPARSE$(str as WSTRING, delimeters as WSTRING, strArray as WSTRING)

Description
Separate elements (i.e., words) of a string into a string array.

Parameters
str â€ââ,¬Å" String to be parsed.
delimeters â€ââ,¬Å" One or more characters used to define where parsing takes place.
strArray â€ââ,¬Å" String array to receive parsed elements of str.

Return Value
Number of parsed elements in the array.

Remarks
See Also: RIGHT$, LEFT$, MID$, LTRIM$, RTRIM$

Example Usage
DEF myArray[] AS STRING    ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å"dynamic string array
DEF iNum AS INTEGER        â€ËÅ"integer value
DEF str AS STRING          ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å"string to be parsed
Str = â€Ã...“However, this is not to say I agree; or something to the effect!â€Ã,
iNum = PARSE$(str, â€Ã...“,; â€Ã...“, myArray)

PRINT iNum
FOR I = 1 to iNum
PRINT myArray[i]
NEXT i

Result
13
however
this
is
not
to
say
i
agree
or
something
to
the
effect



Logman :)
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

sapero

March 18, 2011, 10:09:53 AM #1 Last Edit: March 18, 2011, 10:21:08 AM by sapero
Do you accept this one? ;D
declare cdecl import, strtok(pointer buff, string seps),pointer
declare cdecl import, wcstok(pointer buff, wstring seps),pointer

' pick one of:
'$use "_crtdll.lib"
$use "msvcrt.lib"

' ascii
string Str = "However, this is not to say I agree; or something to the effect!"
pointer token = strtok(Str, ",; ")
while token
print *<string>token
token = strtok(NULL, ",; ")
wend

print
' unicode
wstring wStr = L"However, this is not to say I agree; or something to the effect!"
token = wcstok(wStr, L",; ")
while token
print *<wstring>token
token = wcstok(NULL, L",; ")
wend


The same, but a bit modified - will crearte an array of tokens. The input string must be present while the array is used:
string Str = "However, this is not to say I agree; or something to the effect!"
int count=0
pointer token = strtok(Str, ",; ")
while token
$emit push dword[token]
count++
token = strtok(NULL, ",; ")
wend

if (count)
' now pop the array from stack to a new array
pointer pArray = new(int,count)
$asm
mov ecx,[count]
mov edx,[pArray]
.p:
dec ecx
pop dword[edx+ecx*4]
jnz .p
$endasm
' display
int a
for a=0 to count-1
print *<string>(*<pointer>pArray[a])
next a
delete pArray

' here string Str may be deleted
endif

whitenite1

Okay, here's my wish for the next up-date. Either :

1:   move win, x, y, "Your text goes here!", RGB(r,g,b),RGB(r,g,b)  :' background color, foreground color
2:   print win, x, y, "Your text goes here!", RGB(r,g,b),RGB(r,g,b)   :' background color, foreground color

That I know of, whenever you use the 'move' command, you then use 'print'. So combine the two.
I have many times used the 'move', then forgot to add the 'win', after the 'print'.

Well, this is just a thought.. ( ie. wish)

whitenite1

LarryMc

What's so nice with IWB is you don't have to wait; just roll your own.
Here's the function you are wanting and a demo showing different ways to use it

LarryMc
' Move and Print for whitenite1

window frame
OPENWINDOW frame,0,0,250,200,@MINBOX,0,"Move/Print Demo",&main
centerwindow frame

mprint(frame,10, 10, "red on blue #1", RGB(255,0,0), RGB(0,0,255))

'shows that when using hex it is BGR and not RGB
mprint(frame,30, 30, "red on blue #2", 0x0000ff, 0xff0000)

int x1, y1
x1=50:y1=50
mprint(frame,x1, y1, "red on white #1", RGB(255,0,0), 0xffffff)

x1=70:y1=70
string t
t= "white on green #1"
mprint(frame,x1, y1, t, 0xffffff, RGB(0,255,0))

x1=90:y1=90
t= "white on blue #1"
uint fgc,bgc
fgc=0xffffff : bgc=RGB(0,0,255)
mprint(frame,x1, y1, t, fgc,bgc)

x1=110:y1=110
t= "black on red #1"
fgc=0 : bgc=255
mprint(frame,x1, y1, t, fgc,bgc)

'let's draw a cyan bar (can be used to clear area to background color)
x1=130:y1=130
t= space$(25)
fgc=0 :bgc=0xFAFA00
mprint(frame,x1, y1, t, fgc,bgc)

WAITUNTIL IsWindowClosed(frame)
end

SUB main
select @message
case @IDCLOSEWINDOW
closewindow frame
endselect
RETURN 0
ENDSUB

'just copy this routine to any app you want to use it in.
sub mprint(window w, int x, int y, string text, uint fg, uint bg)
move w,x,y
frontpen w, fg
backpen w,bg
print w, text
return
endsub
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

whitenite1

Larry, thanks for that demo. Works, and looks, GREAT!! I don't know if I'll be as good at programming in this basic as you and some of the programmer on this site. But I'm going to try. Thanks again this sub-routine. I'm definitely going to use it in the next ZX or C=64,  basic converted program I do.

whitenite1