Author Topic: byte pointers how ?  (Read 486 times)

0 Members and 1 Guest are viewing this topic.

Offline Zlatko Vid

  • Full Member
  • ***
  • Posts: 200
  • User-Rate: +0/-0
byte pointers how ?
« on: May 02, 2022, 09:42:57 AM »
Hello Charles

i know that you show me once something similar
but i simply forget how...

my question is how to use

]byte b as strptr(s)
byte b1 as strptr(s1)

and how connect this two strings into one ?

here is my try :
Code: [Select]
'pointer with byte type ...
string s1="Aurel", s3= "_microA"

byte b At strptr s1
byte b1 At strptr s3

bp = b+b1

ps = @bp

'p = @ps

print ps


Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 768
  • User-Rate: +31/-1
    • Charles Pegge
Re: byte pointers how ?
« Reply #1 on: May 02, 2022, 11:30:14 AM »
Hi Aurel,

You will need to add your strings first. Then you have byte access to the whole string.

Code: [Select]
'pointer with byte type ...
string s1="Aurel", s2= "_microA"
string s3=s1+s2

byte b[] at strptr s3 'array of ascii bytes

Offline Zlatko Vid

  • Full Member
  • ***
  • Posts: 200
  • User-Rate: +0/-0
Re: byte pointers how ?
« Reply #2 on: May 02, 2022, 11:37:32 AM »
ahh  i see array of ascii bytes.... i get it
thanks Charles

 in this case  is also same :

Code: [Select]
'string pointer
string s = "viva" ,s2 = " LasVegas",ps
'concat two strings
ps = s+s2
int p As string ptr
' p hold addres of ps
p = @ps

'print
print p

yes i see it now ...ok  :)
 

Offline Zlatko Vid

  • Full Member
  • ***
  • Posts: 200
  • User-Rate: +0/-0
Re: byte pointers how ?
« Reply #3 on: May 02, 2022, 11:45:04 AM »
hmm but how print content of that
array of ascii bytes ?

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 768
  • User-Rate: +31/-1
    • Charles Pegge
Re: byte pointers how ?
« Reply #4 on: May 02, 2022, 12:44:49 PM »
If you don't want to refer to the original string, it is possible to turn the array of bytes back into a string for printing etc.
But both the byte array and the new string are directly coupled to the original string.

Code: [Select]
...
byte b[] at strptr s3 'array of ascii bytes
print b[3]
'
'now reference b as a string again
bstring bs
strptr(bs)=@b
print bs

Offline Zlatko Vid

  • Full Member
  • ***
  • Posts: 200
  • User-Rate: +0/-0
Re: byte pointers how ?
« Reply #5 on: May 02, 2022, 05:47:58 PM »
thanks Charles

i see now where is a trick  :)