Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Split a sting and add missing parts

P675P675 Member Posts: 19
Hello,

I allready have a string converted to a binary code.
Now i want to split the string and if nessesary add 00000000 in the front.
So it can be split by 16 bits.

so if i have 010011010100001001000001 this has to be splited in to

01001101 and 0100001001000001. because the first doesn't has 16 digits 8 have to be added zo it wil be 0000000001001101.

What is the easyest way to split is every 16 digits or 2 characters because the real text is MBA and must be slpit in to M and BA with eight 0's in front of the M. And if it are 4 characters in the real text de eight 0's should be left away.

Kind regards,

P675

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hello,
    :
    : I allready have a string converted to a binary code.
    : Now i want to split the string and if nessesary add 00000000 in the
    : front.
    : So it can be split by 16 bits.
    :
    : so if i have 010011010100001001000001 this has to be splited in to
    :
    : 01001101 and 0100001001000001. because the first doesn't has 16
    : digits 8 have to be added zo it wil be 0000000001001101.
    :
    : What is the easyest way to split is every 16 digits or 2 characters
    : because the real text is MBA and must be slpit in to M and BA with
    : eight 0's in front of the M. And if it are 4 characters in the real
    : text de eight 0's should be left away.
    :
    : Kind regards,
    :
    : P675
    If you know the starting index and length of each piece, then Copy() is the simplest way to split a string. Otherwise you also need Pos() to get the location index of a substring within the main string.
    It is quite simple to prepend a string with 0's to get the correct length. All you need is a while loop and a string addition. Here's an example, which appends 0's to a string until a string is long enough:
    [code]
    while Length(s) < 32 do
    s := s + '0';
    [/code]
Sign In or Register to comment.