Base64 encode Latin 1 string

The app below base64 encodes a Latin 1 string. It seems unaesthetic to first convert to TBytes and then to TIdBytes to be able to call TIdEncoderMIME.EncodeBytes. Is there a simpler way to do this? This is for Delphi XE6 Update 1.

{$apptype console}
program TestEncode;

   System.SysUtils, IdCoder, IdCoderMIME, IdGlobal;

   ISO_8859_1_Code_Page  = 28591;

   ISO_8859_1_String = type AnsiString( ISO_8859_1_Code_Page );

function Encoded( const S: string ): string;

// MIME encode the ISO 8859-1 (Latin 1) string.

   B1: TBytes;
   B2: TIdBytes;
   J:  integer;


   B1 := BytesOf( ISO_8859_1_String( S ) );
   setlength( B2, length( B1 ) );

   for J := low( B1 ) to high( B1 ) do
      B2[ J ] := B1[ J ];

   result := TIdEncoderMIME.EncodeBytes( B2 );


   S: string;


   S := 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ';
   writeln( Encoded( S ) );

7/1/2014 7:23:15 PM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 15
Get it on Google Play
Get it on Apple App Store

David wrote:

> The app below base64 encodes a Latin 1 string.
> It seems unaesthetic to first convert to TBytes and
> then to TIdBytes to be able to call TIdEncoderMIME.EncodeBytes.

TBytes and TIdBytes are both dynamic arrays, so you can use a type-cast to 
avoid the extra conversion:

function Encoded(const S: string): string;
  PIdBytes = ^TIdBytes;
  B: TBytes;
  B := BytesOf(ISO_8859_1_String(S));
  Result := TIdEncoderMIME.EncodeBytes(PIdBytes(@B)^);

A better option is to use EncodeString() instead and let Indy handle the 
byte conversion for you:

function Encoded(const S: string): string;
  Result := TIdEncoderMIME.EncodeString(S, IndyTextEncoding(28591));

Remy Lebeau (TeamB)
7/1/2014 8:56:09 PM
Thank you.
7/1/2014 11:12:00 PM

Similar Artilces:

Translating a Latin-1 string to a UTF8 string in Perl 5.6.1
Now that Perl 5.6.1 has removed support for tr///CU, is there still an easy way to take a latin-1 character string and convert it to a UTF8 string? I need to do that for generating LDIF files to load into an LDAP server.=20 I saw mention of using pack('U0',...), but I can't figure out how that actually works. E.g. Given a variable $string with a value of '=C1ine', I'd like to get the corresponding string in utf8. -- Michael A. Grady Senior Research Programmer Comp...

To Encode String or to Not Encode String... Answer?
I am importing a CSV file from a Unix server as a string, and then saving the string into a new file for later processing.  However, this process does not always work.  As this CSV file is VERY, VERY large, I am unable to immediately tell if the fault lies with my code, or the CSV file provider (very possible).  The only time I can tell that this happened is when the data is not populated the next morning.  The fault appears to lie in there being extra or missing commas, as when I try to run the data import manually, STRINGs are attempted to be inserted into INT...

Encoding a string to base64
Hi, I recently downloaded a source code (n_cryptoapi) which i have tried using to encode a string to base64 but i'm getting incorrect results. string = 0116112006003 actual result = MAAxADEANgAxADEAMgAwADAANgAwADAAMwA= expected result = MDExNjExMjAwNjAwMw what am i doing wrong? I'm using the encode64 function = String ls_encoded ULong lul_len, lul_buflen Boolean lb_rtn lul_len = Len(ablob_data) lul_buflen = lul_len * 2 ls_encoded = Space(lul_buflen) lb_rtn = CryptBinaryToString(ablob_data, & lul_len, CRYPT_STRING_BASE64, & ls_encoded, lu...

string freeze for mozilla 1.8, firefox 1.1 and thunderbird 1.1?
I was looking at the Summary of Upcoming Mozilla Releases on and it doesn't say anything about the time frames that localizers will have to prepare the translation for these products. So, I would like to know when will the string freeze happen for these three? Will it be in Beta2, RC, Developers Preview? I would also like to know if the string freeze is going to be simultaneous for all three, or not? Thanks. -- Novica Novica Nakov schrieb: > I was looking at the Summary of Upcoming Mozilla Releases on >...

Base64 encode zipped string
Hello Group, I want to create a set of functions that allows me to do the following: function CompressAndEncodeString(InString: string): string; begin CompressInString using zip algo or whatever Base64 encode compressed Instring and assign to result end; and function RetrieveString(Instring: string): string begin Base64 decode Instring Uncompress decodestring and assign to result end; Googled for the different parts, but got lost in the complexity. Any help is very much appreciated! Willem -- Willem van Deursen, The Netherlands wvandeursen_nospam@...

check if string is base64 encoded
hey allcurrently i use the following piece of code to check if the string passed to me can be converted to base64, it is not very efficient and bad, can someone please suggest another of doing thisprivate string ConvertBase64ToString(string[] content){StringBuilder sb = new StringBuilder();int i = content.GetUpperBound(0);for (int j=0; j<i; j++){try{// if successful in converting base64 append;}catch (Exception){// cannot be decoded so append the original stringsb.Append(content.GetVa...

not ok 83 # - 0130 - LATIN CAPITAL LETTER I WITH DOT ABOVE - 0069 - I
ive been getting these lately, I thought it might be my setup, but I figured Id better let you decide that for yourselves. ok 82 # - 012E - LATIN CAPITAL LETTER I WITH OGONEK - 012F - C not ok 83 # - 0130 - LATIN CAPITAL LETTER I WITH DOT ABOVE - 0069 - I - 1 1 1 1 0 1 0 0 not ok 84 # - 0131 - LATIN SMALL LETTER DOTLESS I - 0069 - I - 1 1 1 1 0 0 0 0 ok 85 # - 0132 - LATIN CAPITAL LIGATURE IJ - 0133 - C one other unrelated observation. config-args below is missing the -Duseithreads, but it built that way, as is evident from 'usethreads=define' this might be ...

delphi.internet.winsock: text and base64
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_18c8b.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" See message in delphi.internet.winsock group. --JivePart=_18c8b.zeB8CwDOH5aMJzMl Content-Type: image/jpeg; name="buffer1.JPG" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="buffer1.JPG" /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zN...

IOS Setup in Delphi help
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_8d526.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" --JivePart=_8d526.zeB8CwDOH5aMJzMl Content-Type: application/msword; name="Create Profile for Delphi.doc" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Create Profile for Delphi.doc" 0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAAFAAAAbwIAAAAAAAAA EAAAcQIAAAEAAAD+////AAAAAGoCAABrAgAAbAIAAG...

getting base64 encoded string using IdHttp
yes hello good to be back... so i have written a REST server in PHP to talk to my IdHttp client that base64 encodes a jpeg in order to send the data in a record "packet" of my own design. I then use a TStringList.delimitedText to read the received packet and parse the results into key/value pairs (kind of a homestyle JSON format). this is working well for all the other data, but it seems that the base64 field is being limited to 4096 bytes when i call the RawByteString thumb64 := tsServerReply.Values['base64field']; the original 'base64field' i...

Encode string to html string
I need to convert a text string ("Dewey & Cheatham & Howe") to an XML encoded string ("Dewey & Cheatham & Howe"). I am not building an XML document, I am just trying to convert a single string. I have looked at the System.Xml namespace, but I can't quite find what I need. XmlTextWriter.WriteString() does the type of encoding I need, but it writes the string. I just want it to return the encoded string. Can someone tell me the class and method I need? Thanks. Pro LINQ: Language Integrated Query in C# 2008http://www.linqdev.com

charset/base64 encoding/encode.
Still futzing around with email and character sets. Under Encode and perluniintro there's mention of octet \x{..} (255 chars up to \xff string some internal representation code point \x{...} 1, 2 or more bytes of data But I'm not sure about the order of things. So I'll try this: I have a MIME messsage part like the following: Content-Type: text/plain; charset="BIG5" Content-Transfer-Encoding: base64 1eLKx9K7t+JIVE1MuPHKvdDFvP6joQ0KCqFYoVihWKFYoVihWKFYoVihWKFYoVihWKFYoVihWKFY oVihWKFYoVihWKFYoVihWKFYoVihWKFYoVihWAqhaapgt06haqRX...

Encoding image to base64 string using javascript?
I need to encode an image to a base64 string on client side, does anyone has a script to do it? ThanksIf this post has been useful to you please mark it as answer. Take a look at this url, I think it contains the info you are looking for:  I tried that but couldn't manage to get it to work.If this post has been useful to you please mark it as answer....

[PATCH] string encoding for ISO 8859-1
--=-ksx2LhHNUfK9y24TTmGu Content-Type: text/plain Content-Transfer-Encoding: 7bit All -- My computer uses the ISO8859-1 encoding natively, and I figure we eventually want to be able to transode from whatever the specific native encoding is to Unicode. So, I copied strnative.* and did some basic editing to produce striso8859_1.*. The problem is, what I've done really doesn't deal with the issues. I may be misunderstanding, but I think 'strnative' needs to go away and we need to determine the precise native encoding, and call the string encodings what they are....

Web resources about - Base64 encode Latin 1 string - embarcadero.delphi.winsock

Base64 - Wikipedia, the free encyclopedia
The particular choice of character set selected for the 64 characters required for the base varies between implementations. The general rule ...

gnu-pricing/base64 at master · diafygi/gnu-pricing · GitHub
gnu-pricing - Turn GNU command line tools into SaaS (Stupid Hackathon Project)

Error'd: Base64 encoding is actually Finnish?
"Hold up GMail, you mean that Base64 encoding is actually Finnish? Consider my mind blown." wrote Steven Mocking . "It seems the last time I ...

I was asked about base64 vs a sprite image in CSS →
Jake Archibald:With base64 the image data is in the css file, meaning it gets downloaded even if it isn't needed. Eg, if you're using media queries ...

Usenet - Wikipedia, the free encyclopedia
A diagram of Usenet servers and clients. The blue, green, and red dots on the servers represent the groups they carry. Arrows between servers ...

Index Librorum Liberorum
Fourmilab Site Map by John Walker Items which span more than one category are listed in all. Questions and Answers New and Improved Search Access ...

Network Solutions WHOIS Firefox and IE Search Plugin/Provider (JavaScript addEngine)
I prefer Network Solutions' WHOIS service over others because it appears to be one of the more complete and accurate WHOIS services available. ...

List all installed and available Perl modules
... UL++ P L++ E- W++ N+ o K- wO M- V- PS++ PE++ Y+ PGP- t 5 X+ R- tv b+ DI+ D+G e h! r y++ END GEEK CODE BLOCK mail: perl -e 'use MIME::Base64; ...

ActBlue — Introduction to the ActBlue Contributions API
A contribution captures a single event that takes place as a result of a source contributing to one or more entities. It is the root object that ...

JSONVid: Pure JavaScript Video Player
My first thought was to read binary video files using a technique like the Andy Na posted about here , figuring that there must be some really ...

Resources last updated: 12/30/2015 7:24:05 PM