Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Concat a space in a string?

Have an array of char as part of a record...

name: array[0..35] of char;

Using BlockRead, I read from a binary file and get data into this field.

So afterwards, I'm trying to place this field into a FoxPro with a field that is of type FTString. A direct assignment doesn't work, so I wrote a loop to loop thru the characters and concat them in a new string and then assign that string to the table.

The problem now is that if there are spaces in the array, it doesn't get concatenated.

For example, suppose my array look like this:
'P','R','O','G','R','A','M','M','E','R','S', ' ', 'H','E','A','V','E','N'

My resulting string ends up being:
PROGRAMMERSHEAVEN instead of PROGRAMMERS HEAVEN

I'm currently using the concat function....is there another way to do this...but get the correct string?

Thanks.

Comments

  • zibadianzibadian Posts: 6,349Member
    : Have an array of char as part of a record...
    :
    : name: array[0..35] of char;
    :
    : Using BlockRead, I read from a binary file and get data into this field.
    :
    : So afterwards, I'm trying to place this field into a FoxPro with a field that is of type FTString. A direct assignment doesn't work, so I wrote a loop to loop thru the characters and concat them in a new string and then assign that string to the table.
    :
    : The problem now is that if there are spaces in the array, it doesn't get concatenated.
    :
    : For example, suppose my array look like this:
    : 'P','R','O','G','R','A','M','M','E','R','S', ' ', 'H','E','A','V','E','N'
    :
    : My resulting string ends up being:
    : PROGRAMMERSHEAVEN instead of PROGRAMMERS HEAVEN
    :
    : I'm currently using the concat function....is there another way to do this...but get the correct string?
    :
    : Thanks.
    :
    You could try one of the following codes (for each code s=resulting string):
    [code]
    s := name;
    [/code]
    or
    [code]
    SetLength(s, 36);
    for i := 0 to 35 do
    s[i+1] := name[i];
    [/code]
    or
    [code]
    SetLength(s, 36);
    Move(Name, s[1], SizeOf(Name));
    [/code]
    I've tested the first successfully.
  • delphi_noobdelphi_noob Posts: 7Member
    The direct assignment did the trick.

    Thanks!

    : [code]
    : s := name;
    : [/code]

Sign In or Register to comment.