IonicWind Software

IWBasic => General Questions => Topic started by: ckoehn on January 18, 2016, 09:20:51 AM

Title: ISTRING as an argument
Post by: ckoehn on January 18, 2016, 09:20:51 AM
Why doesn't this work?  Is it not possible to pass an ISTRING as an argument and modify the contents?
Change the ISTRING to STRING and it will work.

OPENCONSOLE

ISTRING sel[80000]

sel="This is a test"+chr$(13)+chr$(10)+"this is another line"+chr$(13)+chr$(10)+"This is the third line"+CHR$(13)+CHR$(10)

print sel

Replace(sel,CHR$(13)+chr$(10)," ~ ")

print sel

do:until INKEY$<>""
CLOSECONSOLE
END

SUB Replace(ISTRING txt,STRING sch,STRING rch)
UINT ri

ri=INSTR(txt,sch,1)
WHILE ri>0
txt=LEFT$(txt,ri-1)+rch+MID$(txt,ri+LEN(sch))
ri=INSTR(txt,sch,ri+LEN(rch))
ENDWHILE
ENDSUB


Later,
Clint
Title: Re: ISTRING as an argument
Post by: Andy on January 18, 2016, 10:15:35 AM
Clint,

Not quite sure what you are trying to get here, It's probably the CHR$(13) that's the problem.

Anyway, have you tried My StringTheory code yet?

Here is the link:
http://www.ionicwind.com/forums/index.php?topic=5802.0

Go to near the end to download Stringtheory4.zip, install it (read the help file) and then you can run the code attached here.

Think it will help you do what you want more easily.

Andy.
:)
Title: Re: ISTRING as an argument
Post by: LarryMc on January 18, 2016, 10:38:22 AM
Clint
You didn't declare your Replace function properly for an ISTRING
It should have been this
SUB Replace(ISTRING txt[80000],STRING sch,STRING rch)

see here:
http://www.ionicwind.com/forums/index.php?topic=3264.msg26530#msg26530
sorry
Notes:
-------------------------
ISTRING/IWSTRING changes
The ISTRING and IWSTRING keywords can now be used in a subroutine parameter list to pass arrays.  For example:


istring nn[11,2]
nn[0,0] = "hellohello"
nn[0,1] = "goodbye"

test(nn)

sub test(name[11,2] as istring)
print name[0,0]
print name[0,1]
endsub

do:until inkey$ <> ""


When using the keywords with a single dimensioned ISTRING/IWSTRING you still need to specify the dimension in the parameter list, or just use the STRING/WSTRING types.  For example:


istring name[50]
name = "John Smith"
test1(name)
test2(name)

sub test1(txt[50] as istring)
  print txt
endsub

sub test2(txt as string)
  print txt
endsub

Title: Re: ISTRING as an argument
Post by: ckoehn on January 18, 2016, 10:51:15 AM
Ahh.. thanks Larry.  I knew it was something simple.

Andy: I looked at your offering before you changed it to a lib and you did searches a character at a time.  My understanding would be that INSTR is much faster since it is a native command.  Maybe someone can help me out on that.

I know that what I am doing is very fast once its loaded in memory.  I am searching in 1,930 text files, with over 95Mb of data in a little under 2 sec.  It does depend on your computer and I do have a fast one.  But even on a slow one it is never over 5 - 8 secs.

Later,
Clint
Title: Re: ISTRING as an argument
Post by: aurelCB on January 19, 2016, 01:40:16 AM
hi guys
if someone need Replace$ function here is one you can modify:

Function Replace(string t,w,r) as string
 '=======================================
 '
 int a,b,lw,lr
 string s=t
 '
 lw=Len(w)
 lr=Len(r)
 a=1
 '  
 do
   a=Instr(a,s,w)
  ' If a=0 then exit do
   s=Left(s,a-1)+r+Mid(s,a+lw)
   a+=lr
 until a<>0
 Return s
End Function


..also don't forget ISTRING is limited by default to 16848, long time ago i try to increse this
number but without succes...
Title: Re: ISTRING as an argument
Post by: ckoehn on January 19, 2016, 06:24:09 AM
I don't understand what you mean by this..
Quote..also don't forget ISTRING is limited by default to 16848, long time ago i try to increse this
number but without succes...

The files that I load are around 75,000 bytes and they fit in an ISTRING txt[80000] without any loss of characters.

Later,
Clint
Title: Re: ISTRING as an argument
Post by: aurelCB on January 20, 2016, 01:33:29 AM
oups i made mistake
it is 168484