William23668 8 Posted December 25, 2021 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
David Heffernan 2345 Posted December 25, 2021 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
William23668 8 Posted December 25, 2021 (edited) 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 December 25, 2021 by William23668 Share this post Link to post
David Heffernan 2345 Posted December 25, 2021 (edited) 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 December 25, 2021 by David Heffernan 1 1 Share this post Link to post
William23668 8 Posted December 25, 2021 4 minutes ago, David Heffernan said: Should be #0 rather than '#0' love you. many thanks Share this post Link to post
David Heffernan 2345 Posted December 25, 2021 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. 1 Share this post Link to post
David Heffernan 2345 Posted December 25, 2021 Also, this isn't how to display binary in a hex editor. Share this post Link to post
William23668 8 Posted December 25, 2021 7 minutes ago, David Heffernan said: Also, this isn't how to display binary in a hex editor. No it was just to practice. Share this post Link to post
limelect 48 Posted December 31, 2021 Try using RxStrUtils in unrxlib function ReplaceStr(const S, Srch, Replace: string): string; 1 Share this post Link to post
David Heffernan 2345 Posted December 31, 2021 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
David Heffernan 2345 Posted December 31, 2021 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