|
|
| Author |
Message |
victorf
Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York
|
|
Posted: 13 January 2006, 2:36 AM Post subject: String variable |
|
|
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
Any enlightenment will be appreciated.
Vic |
|
| Back to top |
|
 |
DH* Guest
|
|
Posted: 13 January 2006, 3:12 AM Post subject: |
|
|
Look at the following functions in the System Library Reference...
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: |
|
|
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 |
|
 |
|