find and replace text
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by redacid.
Fred: the source Danilo sent to you is exactly the same way as I tried it.
It just didn`t work on my machine:
PB2.70, WinXP-Pro, Gericom Notebook, 1,1GHz, 256MB RAM, 20GB HD, DVD, 1024x768x16.
If you need a "better" test, just tell me what I have to do and I will test it.
Fred: the source Danilo sent to you is exactly the same way as I tried it.
It just didn`t work on my machine:
PB2.70, WinXP-Pro, Gericom Notebook, 1,1GHz, 256MB RAM, 20GB HD, DVD, 1024x768x16.
If you need a "better" test, just tell me what I have to do and I will test it.
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Ralf.
the programms works only with small files ?
when i use a file with 1 Kb it works, when i use
a file with 27 Kb it doesn't work.
Is the filesize limited ?
1.) Use Repeat... Until together with EOF()
2.) Use Readfile, not Openfile for the 1st file..
Procedure.s Replace(S$,R$,N$) While FindString(S$,R$,1)>0 S$=Left(S$,(FindString(S$,R$,1)-1))+N$+Right(S$,Len(S$)-(FindString(S$,R$,1)+Len(R$)-1)) Wend ProcedureReturn S$ EndProcedure ;---------------------------------------------------------------------- If ReadFile(0, "D:\TEST\DTA.TXT") If OpenFile(1, "D:\TEST\DTA2.TXT") Repeat UseFile(0) TEMP.s = ReadString() TEMP.s = Replace (TEMP.s, "0128AGK", "5555AFP" ) UseFile(1) WriteStringN(TEMP.s) Until Eof(0) 0 EndIfEndIfEnde:CloseFile(0) CloseFile(1)
cya,
...Danilo
(registered PureBasic user)
the programms works only with small files ?
when i use a file with 1 Kb it works, when i use
a file with 27 Kb it doesn't work.
Is the filesize limited ?
1.) Use Repeat... Until together with EOF()
2.) Use Readfile, not Openfile for the 1st file..
Procedure.s Replace(S$,R$,N$) While FindString(S$,R$,1)>0 S$=Left(S$,(FindString(S$,R$,1)-1))+N$+Right(S$,Len(S$)-(FindString(S$,R$,1)+Len(R$)-1)) Wend ProcedureReturn S$ EndProcedure ;---------------------------------------------------------------------- If ReadFile(0, "D:\TEST\DTA.TXT") If OpenFile(1, "D:\TEST\DTA2.TXT") Repeat UseFile(0) TEMP.s = ReadString() TEMP.s = Replace (TEMP.s, "0128AGK", "5555AFP" ) UseFile(1) WriteStringN(TEMP.s) Until Eof(0) 0 EndIfEndIfEnde:CloseFile(0) CloseFile(1)
cya,
...Danilo
(registered PureBasic user)
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.

PB - Registered PureBasic Coder
Here's my solution. Works with a 672 Kb file, too.the programms works only with small files ?
when i use a file with 1 Kb it works, when i use
a file with 27 Kb it doesn't work.
Is the filesize limited ?

Code: Select all
Procedure$ replace(string$,old$,new$)
r=1 : pos=1
While r0
r=FindString(string$,old$,pos)
If r0
string$=Left(string$,r-1)+new$+Mid(string$,r+Len(old$),Len(string$))
pos=pos+Len(new$)
EndIf
Wend
ProcedureReturn string$
EndProcedure
;
If ReadFile(0,"c:\original.txt")
If CreateFile(1,"c:\modified.txt")
Repeat
UseFile(0)
s$=ReadString()
s$=replace(s$,"0128AGK","5555AFP")
UseFile(1)
WriteStringN(s$)
Until Eof(0)0
EndIf
EndIf
PB - Registered PureBasic Coder
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
Fred - AlphaSND
Bug found and fixed.Code: Select all
;---- OpenConsole() If OpenFile(0, "C:\TEST.PB") UseFile(0) TEMP.s = ReadString() PrintN(TEMP.s) Delay(3000) CloseFile(0) EndIf ;----
Fred - AlphaSND
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm