June 25, 2024, 05:24:35 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


ISTRING as an argument

Started by ckoehn, January 18, 2016, 09:20:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ckoehn

January 18, 2016, 09:20:51 AM Last Edit: January 18, 2016, 09:42:49 AM by ckoehn
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

Andy

January 18, 2016, 10:15:35 AM #1 Last Edit: January 18, 2016, 10:28:29 AM by andy1966
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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

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

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

ckoehn

January 18, 2016, 10:51:15 AM #3 Last Edit: January 18, 2016, 11:04:21 AM by ckoehn
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

aurelCB

January 19, 2016, 01:40:16 AM #4 Last Edit: January 19, 2016, 01:43:15 AM by aurelCB
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...

ckoehn

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

aurelCB

oups i made mistake
it is 168484