BBC BASIC for Windows
« Converting array into a String$ »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:49pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Converting array into a String$  (Read 649 times)
wyzeowl
New Member
Image


member is offline

Avatar




PM


Posts: 5
xx Converting array into a String$
« Thread started on: Sep 19th, 2010, 3:23pm »

I am trying to write a program to read data via the serial port. Once collected the data is 11 or 12 charracters long. My problem is the incoming data is stored in an array but to process it i need it as a string.
Any thoughts anybody
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Converting array into a String$
« Reply #1 on: Sep 19th, 2010, 5:08pm »

on Sep 19th, 2010, 3:23pm, wyzeowl wrote:
My problem is the incoming data is stored in an array but to process it i need it as a string.
Any thoughts anybody

I know it's not exactly answering the question, but could you not store it in a string to start with? Something like:

Code:
      serial$ += CHR$(BGET#chan%) 

If you really must convert a byte array to a string (and this will only work with a byte array, not an integer array) then - assuming there is at least one empty element after the true end of the string - you can use:

Code:
      string$ = $$^array&(0) 

If necessary empty the array before you start filling it again:

Code:
      array&() = 0 

Here's a test program:

Code:
      DIM array&(255)
      array&() = &54,&65,&73,&74
      string$ = $$^array&(0)
      PRINT string$ 

Richard.
User IP Logged

wyzeowl
New Member
Image


member is offline

Avatar




PM


Posts: 5
xx Re: Converting array into a String$
« Reply #2 on: Sep 19th, 2010, 9:23pm »

Richard, Thankyou for the reply. I will need to digest what you have written. I will get back to you.
One question ,What does the serial + command do? That looks like promising path to tread.

User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Converting array into a String$
« Reply #3 on: Sep 19th, 2010, 9:33pm »

on Sep 19th, 2010, 9:23pm, wyzeowl wrote:
One question ,What does the serial + command do? That looks like promising path to tread.

The compound += operator is used to add something to an existing variable. So:

Code:
      serial$ += CHR$(BGET#chan%) 

is shorthand for:

Code:
      serial$ = serial$ + CHR$(BGET#chan%) 

(it executes a little faster too). In this context you can use it to build up a string character-by-character.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls