Moving data to procedure and text manip

Just starting out? Need help? Post your questions and find answers here.
neomember
User
User
Posts: 14
Joined: Tue Jul 27, 2004 12:17 am

Moving data to procedure and text manip

Post by neomember »

I need a way to read data from a file and to pass it to a few procedures for treatments.

I want to do some 'search and replace' for multiples items at the same time.

I want to remove/replace multiple HTML tags in a document.

I have already a procedure made by Droopy to "construct" the string to be removed. It worked well for a simple string variable but i need to apply the procedure to a whole document. I've tried to read the document to a linked list but i'm not able to pass that list to the procedure.

Here's the procedure from the Tips 'n Tricks section:
http://www.purebasic.fr/english/viewtopic.php?t=18665

I will probably have at least another procedure to do the string replacements also.

The size of these documents should never exceed 1024Kb for most of the time.

What would be the best way to read the data in memory?? Should i allocate memory... use a linked list??

How can i pass lots of data to/from a procedure??

For now, the program is only able to process one tag at a time. My goal is to call a 'search/replace' procedure multiple times using a different tag as an argument each time. Is it an effective way to do this??

If been thinking about regexp implementation also... but i haven't look for it yet.

Thanks in advance!!!
Last edited by neomember on Thu Mar 09, 2006 10:51 pm, edited 1 time in total.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Did you try to put your file to a string like this ?

Code: Select all

String.s=""
ReadFile(0,filename.s)
While Eof(0)=0
  String+ReadString()+#CRLF$
Wend
CloseFile(0)
neomember
User
User
Posts: 14
Joined: Tue Jul 27, 2004 12:17 am

Post by neomember »

As in the PB 3.92 HTML Help file:
Lists are always globally accessable in PureBasic. This means that they can always be accessed from inside procedures without needing to use the Global or Shared commands.

Taken from: http://www.xs4all.nl/~bluez/datatalk/pu ... procedures
As of PB v4.00 arrays and lists are no longer automatically global. If you want to access them from within a procedure, you either have to define them as global or you have to pass them as a parameter during the procedure call.
I have two pieces of codes that recreates the problem. One for PureBasic 3.9x, the other is for PureBasic 4.0. Neither of them compile at the moment (in PureBasic 3.92).

The first one is for PB 3.9x

Code: Select all

 Procedure test_list()
  AddElement(x())
  x() = "Inside Procedure"
  Debug x()
 EndProcedure


 NewList x.s()
  AddElement(x())
  x() = "Outside Procedure"
  
  ; test_list()
  
 Debug x()
Here's the other for PB 4.0:

Code: Select all

OpenConsole()
  ;
  ; try a list as a parameter
  ;
  NewList x.l()
  AddElement(x())
  x() = 1
  ;
  Procedure test_list(y())
    SelectElement(y(),1)
    y() = 2
  EndProcedure
  ;
  test_list(x())
  SelectElement(x(),1)
  PrintN("list: "+Str(x()))
I'm obviously doing something wrong.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Like this ? (PB 3.94)

Code: Select all

NewList x.s() 

Procedure test_list() 
  AddElement(x()) 
  x() = "Inside Procedure" 
  Debug x() 
EndProcedure 



AddElement(x()) 
x() = "Outside Procedure" 
  
  ; test_list() 
  
Debug x()
neomember
User
User
Posts: 14
Joined: Tue Jul 27, 2004 12:17 am

Post by neomember »

Man... i'll remember this for the rest of my life!!!

Thank you!!!
Sub-Routine
User
User
Posts: 82
Joined: Tue May 03, 2005 2:51 am
Location: Wheeling, Illinois, USA
Contact:

Post by Sub-Routine »

You should realize that the first element in a linked list is x(0), I think that may be a mistake in your PB4 example.

Example for 3.94:

Code: Select all

NewList x.s() 

Procedure test_list() 
  AddElement(x()) 
  x() = "Inside Procedure" 
  ; Debug x() 
EndProcedure 

For X = 0 To 2
  AddElement(x()) 
  x() = "Outside Procedure" 
  test_list() 
; Next
  
  ForEach x()
    Debug "List Index = " + Str(ListIndex(x()))
    Debug  "List Data: " + x()
  Next
  Debug ""
Next
Rand
Post Reply