How is a string in an array of strings terminated ?
Do I have to add a certain character myself #CR$ ? this works .
Do I have to determine the string length first?
What is the best way ?
Dim text.s(100) ;array of string
l.i ;length string
text(1)="text1"+ #CR$ ;add an extra #CR$
text(2)="This is text2"
l=Len(text(2))*2 ;length of string
*t=@text(2)
While n=< l ;this work ,but need length of string
kar.a=PeekA(*t+n)
Debug Chr(kar)
n=n+2
Wend
;------------------------------------
n=0 ;reset n
*t=@text(1)
Repeat
kar.a=PeekA(*t+n)
Debug Chr(kar)
n=n+2
Until kar=#CR ;
debug kar ;read 13 ,it works
An array of string is an array of pointer to string. A string variable is always the pointer to the string. Thus, the strings in the array are necessarily one after the other in the memory.
If there is not enough space for the new string in the array, a new memory is requested and the old one is released.
Structure s1
s$[3]
EndStructure
Dim s$(2)
Define s.s1
For i = 0 To 2
s$(i) = Str(i) + "A"
s\s$[i] = Str(i) + "S"
Next i
ShowMemoryViewer(@s$(0),255)
CallDebugger
ShowMemoryViewer(@s\s$,255)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Don't forget!
You cannot directly add any characters to the string in memory. As shown above, if there is not enough space, a new memory is allocated for the string.
my problem is that I want to read a string from an array, character by character.
Depending on the character I have to do something.
I can first determine the length with LEN (string), but that is more time.
I can add a #CR when creating the strings in the array, in the example I added it later, but it turns out to work.
But maybe it doesn't always work as MK-soft says.
at Skywalk,
I found in C, strings are terminated with a null character (ASCII code 0).Is that what you mean ?
Well, with strings it's important that you understand exactly how it works, it's easy to make mistakes.
For example, you can also create a string from spaces, i.e. an empty one, which is then automatically terminated at the end.
In this string you can insert a #LF$ at any desired position or PokeW two zeros to terminate it.
If your strings never exceed a certain maximum you can pre define and cut them arbitrarily.
A small overhead does not matter.
If you use strings in PB you will always have an overhead, which is much bigger, but not disturbing.
The problem is when you destroy the termination at the end.
Then PB searches for the next occurring two zeros in memory.
You always have to look at what you need.