ptr to string 
Author Message
 ptr to string

I have a pointer with some data in it that I need converted to a text
string. I know I need to loop through each byte of the ptr then put it into
each byte of a text string but I don't how to do this. please help. thanks
all!


Sat, 09 Aug 2003 15:05:17 GMT  
 ptr to string


Quote:
>I have a pointer with some data in it that I need converted to a text
>string. I know I need to loop through each byte of the ptr then put it into
>each byte of a text string but I don't how to do this. please help. thanks
>all!

{This is a puzzling question. A pointer itself has no datum except a
heap memory location where the datum is stored. The datum can already
be a string with no conversion required. If there are several data
pointers within an array of pointers, each of which points to a byte,
you can serially access the array and convert bytes to a chars and
concatenate to a string. Maybe this will help: }

Program PointerDemo;
Var
   sptr:^String;
   b:Array[1..80] of ^byte;
   ct:Byte;
   s1, s2:String;

Begin
     Writeln; Writeln;
     s1 := 'the quick brown fox jumps over the lazy dog';
     New(sptr);
     sptr^ := s1;
     Writeln('From pointer to string: ', sptr^);

     For ct := 1 to 80 Do b[ct] := nil; {Used array length not known}
     For ct := 1 to Length(s1) Do
     Begin
          New(b[ct]);
          b[ct]^ := Ord(s1[ct]);
     End;

     ct := 1; s2 := '';
     While b[ct] <> nil Do
     Begin
          s2 := s2 + Chr(b[ct]^);
          Inc(ct);
     End;
    Writeln('Array of byte pointers: ', s2);
readln;
End.



Sun, 10 Aug 2003 01:48:54 GMT  
 ptr to string

Quote:
> I have a pointer with some data in it that I need converted to a text
> string. I know I need to loop through each byte of the ptr then put it into
> each byte of a text string but I don't how to do this. please help. thanks
> all!

   How you've declared everything makes some difference here.  Show us
your code.


Sat, 09 Aug 2003 22:10:35 GMT  
 ptr to string


Quote:
>> I have a pointer with some data in it that I need converted to a text
>> string. I know I need to loop through each byte of the ptr then put it into
>> each byte of a text string but I don't how to do this. please help. thanks
>> all!

> How you've declared everything makes some difference here.  Show us
> your code.

I have this variable data: ptr with some data in it, text. I need to put its
contents into the variable string[len] len being the length of the data
(number of characters) which I also have. that's all.


Mon, 11 Aug 2003 03:45:55 GMT  
 ptr to string

Quote:



> >> I have a pointer with some data in it that I need converted to a text
> >> string. I know I need to loop through each byte of the ptr then put it into
> >> each byte of a text string but I don't how to do this. please help. thanks
> >> all!

> > How you've declared everything makes some difference here.  Show us
> > your code.

> I have this variable data: ptr with some data in it, text. I need to put its
> contents into the variable string[len] len being the length of the data
> (number of characters) which I also have. that's all.

Hi

The following assumes Borland/Turbo style strings.

var data: pointer;
    st: string [pickasize];
    len: integer;
    MoveCount: integer;
begin
{...}
MoveCount := min (len, sizeof (st)-1);
   {Do this to keep from overrunning the space allocated to st}
move (data^,st [1], MoveCount);
st [0] := chr (MoveCount); {this works in borland Pascal 7}
{...}
end.

Min returns the minimum of two integers, you have to supply the min
function.

Regards Hanford



Mon, 11 Aug 2003 04:58:33 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. 4DA2DE39 cmp dword ptr [edx],$00

2. Ptr Casting syntax??

3. Real: Ptr Casting syntax??

4. ptr to array

5. Prot mode ptr need a touch?

6. Phy addr from prot mode ptr

7. pchar := string; string:=pchar

8. How to convert strings to nul-terminated strings?

9. String vs. String literal

10. String within a String

11. String (swapping two chars in a string)

12. Get error when affect a String Field in a string var

 

 
Powered by phpBB® Forum Software