#111494 - 2004-01-09 05:14 AM
Re: Need Script to replace strings in a text file
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Wow! This is starting to look a lot better than the simple HOSTS change script: Update/change HOSTS file
Kent
|
|
Top
|
|
|
|
#111495 - 2004-01-09 03:37 PM
Re: Need Script to replace strings in a text file
|
@lejo @rias
Starting to like KiXtart
Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
|
Try This... ;to read file and put in array Function ReadFile($file) Dim $lf, $t $lf=Chr(10) $f=FreeFileHandle $=Open($f,$file) If @error Exit @error EndIf Do $t=$t+$lf+ReadLine($f) Until @error $=Close($f) $ReadFile=Split(SubStr($t,2),$lf) EndFunction
;func to replace string a to b Function ReplaceSTR($string, $from, $to) If InStr($string, $from) $string=$to $cont=$cont+1 Exit 0 Else $ReplaceSTR=$string Exit 1 EndIf EndFunction
;func to write array in a new file Function WriteFile($array,$file) Dim $f $f=FreeFileHandle $=Open($f,$file,5) If @error Exit @error EndIf For Each $line In $array $=WriteLine($f,$line + @crlf) Next $=Close($f) Exit @error EndFunction
;cod for replace string in the file using funcs $Usuario_Anterior="xxxx" $Usuario_Actual="yyyy"
$file='%allusersprofile%\Datos de programa\IBM\Personal Communications\Medellin.acg' $arrFile=ReadFile($file) For $line =0 to Ubound($arrFile) $arrFile[$line]=ReplaceSTR($arrFile[$line],$Usuario_Anterior,$Usuario_Actual) Next $=WriteFile($arrFile,$file)
_________________________
Look always 4 the best...
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 565 anonymous users online.
|
|
|