#define REP4(s) ((s)+(s)+(s)+(s))
#define REP256(s) REP4(REP4(REP4(REP4(s))))
Const TwoChars = "Er"
'' constant string (like a literal)
const c as string = REP256( TwoChars )
print c
print len(c)
'' fixed length string that promises to be constant
dim fc as const string * 512 = REP256( TwoChars )
print fc
print len(fc)
'' variable length string that promises to be constant
dim vc as const string = REP256( TwoChars )
print vc
print len(vc)
function MakePair(pair as const string) as const string
dim as ubyte u(511)
for n as long=0 to 511
if n mod 2=0 then u(n)=pair[0] else u(n)=pair[1]
next
return *cast(zstring ptr,@u(0))
end function
dim as const string * 512 a=MakePair("Er")
dim as const string * 512 b=MakePair("Fb")
dim as const string * 512 c=MakePair("Ok")
print a
print b
print c
print len(a),len(b),len(c)
'not allowed:
'a=b
'b="y"
'c="z"
sleep
A predefined 'String()' function exists: Declare Function String(ByVal count As Integer, ByRef ch As Const String) As String
but it only takes into account the first character of 'ch'.
The user can define his own '_String_()' function, but which takes into account all the characters of 'ch':
Function _String_(ByVal count As Integer, ByRef ch As Const String) As String
Dim As String s = String(count * Len(ch), 0)
For i As Integer = 0 To (count - 1) * Len(ch) Step Len(ch)
StrPtr(s)[i] = ch
Next i
Return s
End Function
Dim As String s = _String_(256, "Er")
Print Len(s)
Print s
Sleep
Function Set(n As Long,Chars As String,mode As boolean=false) As String
If mode=true Then n*=Len(Chars)
Var c=String(n,0),count=-1
For m As Long=0 To n-1 Step Len(Chars)
For k As Long=0 To Len(Chars)-1
count+=1
If count>n-1 Then Exit For,For
c[count]=Chars[k]
Next k
Next
Return c
End Function
'mode false = absolute number of characters.
'mode true = number of groups of characters.
Dim As Const String g=Set(200,"Free") '200 characters
Print g
Print Len(g)
Dim As Const String * 512 k=Set(Len(k),"Er")'512 characters
Print k
Print Len(k)
Dim As Const String z=Set(12,"0123456789"+Chr(10),true)'12 groups on a new line each (chr(10))
Print z
Print Len(z)," (12 X 11)"
' not allowed
'g="1"
'k="2"
'z="3"
Sleep
Happy New Year all when it arrives (at various times for forum members), but sometime today.