Jump to content
William23668

stringreplace character in all string

Recommended Posts

 

I have string like this

84@fgl#000^2#0#0 94j@f#0

And I tried to replace all '#0' with '0' like this

 

result := stringreplace(OriginalStr, '#0', '0',[rfReplaceAll, rfIgnoreCase]);

But this did not replace all the '#0' , how I should use this ?

Share this post


Link to post

Can you show what the output of your code is. It should be easy to produce a minimal complete program, a console app, that demonstrates the behaviour that you are struggling with. 

Share this post


Link to post

I test it with this line

 

fstr := 'MZ'#$0090#0#3#0#0#0#4#0#0#0'ÿÿ'#0#0'¸'#0#0#0#0#0#0#0'';
fstr := stringreplace(fstr,'#0','0',[rfReplaceAll, rfIgnoreCase]);

output is (copied from the watch window)

 

'MZ'#$0090#0#3#0#0#0#4#0#0#0'ÿÿ'#0#0'¸'#0#0#0#0#0#0#0

 

Edited by William23668

Share this post


Link to post
50 minutes ago, William23668 said:

fstr := stringreplace(fstr,'#0','0',[rfReplaceAll, rfIgnoreCase]);

Should be #0 rather than '#0'. Your code is replacing the text '#0' which doesn't appear in the string. 

Edited by David Heffernan
  • Like 1
  • Thanks 1

Share this post


Link to post

Big lesson here is always to show a proper minimal but complete reproduction. It wasn't clear what the problem was from the first post which was descriptive. Code doesn't lie.

  • Like 1

Share this post


Link to post

Try using RxStrUtils in unrxlib

function ReplaceStr(const S, Srch, Replace: string): string;
 

  • Like 1

Share this post


Link to post
1 minute ago, limelect said:

Try using RxStrUtils in unrxlib

function ReplaceStr(const S, Srch, Replace: string): string;
 

Why is that better than StringReplace? How does it relate to the problem in this thread? 

Share this post


Link to post
4 hours ago, limelect said:

One more information

I'm sure your function would give the same result. Did you read the earlier posts? They explain what is going on. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×