Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
String variable

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 13 January 2006, 2:36 AM    Post subject: String variable Reply with quote

How is a string variable configured. Is it an array of bytes? Is it a null terminated string of bytes? For example, in Pascal a string is a zero based array of char (byte) with the byte at a(0) holding the number of actual chars in the string. One can use this knowledge to iterate thru the string a(1) . . . a(n) and a(0) would contain n. I would like to be able to do this in ZBasic.

Anyone have a nifty string parser Question

Any enlightenment will be appreciated.

Vic
Back to top
DH*
Guest





Posted: 13 January 2006, 3:12 AM    Post subject: Reply with quote

Look at the following functions in the System Library Reference...
    Asc
    Len
    Mid
    StrAddress
And see Section 2.11 in the Language Reference Manual.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 13 January 2006, 4:16 AM    Post subject: Reply with quote

For implementation details, see Section 3.21.1

The cleanest way to index through the characters of a string is to use the Asc() function. The second parameter, which is optional, specifies the 1-based index of the character of the string to return. If not specified, it defaults to 1. An example of processing the characters of a string using this technique is shown below.

Code:
Sub Main()
   Dim s as String
   Dim i as Integer, cnt as Integer
   Dim c as Byte
   s = "The quick brown fox jumped over the lazy dog."
   
   ' process the string
   cnt = len(s)
   For i = 1 to cnt
      ' fetch the next string character
      c = Asc(s, i)

      ' if it's not a space, increment the character value
      If (c <> &H20) Then
         c = c + 1
      End If

      ' display the character
      Debug.Print Chr(c);
   Next i
   Debug.Print
End Sub


Another way to accomplish the same objective is to use the StrAddress() and StrType() functions. This is more complicated because the address returned by StrAddress() can be a RAM address, a Program Memory address or an PersistentMemory address depending on the the way that the code is written. StrType() return an indicator that specifies where the string resides.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group