AnsiReplaceString DON'T WORK: Replace some characters in a String with bynary contents

Hi Experts, i have to encrypt a string that contains some plain text.
After encryption the contents of the string have any kind of character.
In this resulting string, i need to replace some characters, for example "|" to "\|".
I was trying to do this with AnsiReplaceString supplied by delphi (version 7), but it not seems to work (no replace is made).

Have you any idea?

Best regards
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The standard method for what I think you are attempting to do do the following

Encoding Phase

1) Compress original string (optional)
2) Encrypt
3) base64 encode

Now is it safe to transmit, store, etc. the encoded data

Decoding Phase

1) base64 decode
2) decypt
3) uncompress (if compressed)

Look up base64 encoding/decoding and you will understand why this is used. Delphi source for base64 encoding is fairly easy to find too

hello  balrom, , I do not know the encryption that you use, but many encryptions  DO NOT  encrypt  ANSII text to ANSII text, but will have  "have any kind of character" which you discribe (acually there are NO CHARACTERS  in it at all, since it is now digital data, not text data). . .  almost all of the String functions will STOP their procedure for scanning through a strng, whenever they get to a Byte in the string with a value of zero, #0,, which is the famous Null Character,  so if your encyipted text has any zero value bytes in it, then the AnsiReplaceString may not work with it. . .

 I would wounder why you would need to do any AnsiReplaceString kind of thing after you encrypt it, , shouldn't you do that before you encrytp it? ?
All Ansi functions handle MCBS strings so you get problems with your encrypted strings.
A peek at the sources reveals that AnsiReplaceStr uses AnsiPos which handles MCBS.
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

balromAuthor Commented:
Thank you for your replies.

gwalkeriq: I don'w want to use base64 encoding, it increase the size of final string (about 1/3).

Slick812: I need to do the replace after enctyption.

robert_marquardt: If Ansi functions don't work on this type of content, it there an alternative function?

Best regards
if wou whant to replace char (string) with another char (string) I will recomand to use FastReplace --> FastStrings routins find at 

this it's Product Information:

A useful set of assembly optimised string manipulation routines. The most remarkable of these is without a doubt the FastReplace function. StringReplace took over 8 hours to complete multiple replacements on a 10mb string, whereas FastReplace took 0.5 seconds (yes, half of a second).

A set of string routines for manipulating large strings at high speed.

Includes Boyer-Moore searching algorithm, backwards string searching, and a very high-speed alternative for StringReplace.

In short, postcard ware means that you can use this source code in your own commercial applications. You cannot copy or modify the source code unless you send me a copy so that I may review it for possible inclusion. You must also obtain permission from me before using this library (Just send my children a postcard)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
balromAuthor Commented:
Thanks carcotasu, a very nice set of fast functions...
I've tested it and works fine!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.