SRL Archive - OSR Help

TReplaceFlags ?


Bobzilla69

2011-02-01 04:48:37

Hey,

so i need to use TReplaceFlags but i dont have a clue how to declare them or what they are in simba.

its needed for Replace();

couldn't see anything in the documentation.

any help?

Sex

2011-02-01 10:10:59

rfIgnoreCase, rfReplaceAll

Like Replace('blah', 'blah', [rfReplaceAll])

Gu3st...

2011-02-01 11:47:37

^That, or do [] if you don't know what does what
Replace(….. []);

Markus

2011-02-01 12:14:04

There are two replaceflags, rfReplaceAll or rfIgnoreCaps
Use them in an array.
Without rfReplaceAll it'll only replace the first instance.
Demo:

program new;
begin
writeln(replace('bOt rot tot kot vOt', 'ot', 'at', []));
writeln(replace('bOt rot tot kot vOt', 'ot', 'at', [rfReplaceAll]));
writeln(replace('bOt rot tot kot vOt', 'ot', 'at', [rfIgnoreCase]));
writeln(replace('bOt rot tot kot vOt', 'ot', 'at', [rfIgnoreCase, rfReplaceAll]));
end.

Pure coincidence that I asked this yesterday @ #SRL myself? =)

Bobzilla69

2011-02-01 14:53:12

hmmm, i googled it before posting and found that but when i tried it didnt work, must have typed it wrong.

thanks for answers and will try later

nielsie95

2011-02-01 16:17:48

A little tip if you want to know more about a type: use code completion. Type TReplaceFlags and hit ctrl+space. You'll see that it says "TReplaceFlags: set of TReplaceFlag". Now do you the same for TReplaceFlag and you'll find that it's an enumeration of rfReplaceAll..rfIgnoreCase. If the enum follows the convention it has a certain prefix (in this case "rf"). Now type in rf and hit ctrl+space again to find all your possible options (make sure they have "(TReplaceFlag)" behind them).

Bobzilla69

2011-02-02 05:14:31

Thanks for the pro tip, will help alot :)

edit:

doesnt work for me :(

procedure UpdateString;
var
text, after:String;
i:integer;
begin
Accounts:= OpenFile(Path + '1.xml' , False);

ReadFileString(Accounts, text, FileSize(accounts));

after:= replace(text, 'test', 'Character', [rfIgnoreCase]);

writeln(text);
writeln(after);

CloseFile(Accounts);
end;

i get [Error] (124:61): Invalid number of parameters at line 123;

which is the after:= replace(); section.

Bonfield

2011-02-02 06:50:15

Remove the var text and it should work

Bobzilla69

2011-02-02 07:16:12

but "Text" is the string to search in?

  replace(Text:String;FindStr:String;ReplaceStr:String;Flags:TReplaceFlags):String; 

is whats its asking for….

but i will try.

Edit:

Code Hint is wrong for replace.

after:= Replace(text, 'test', 'Character');  
works fine, no need for the Flags

if you type Replace then Ctrl + Space it shows the correct variables needed

The code hint its showing is for ReplaceWrap();