PDA

View Full Version : Usage of the STRING$ keyword



Michael Clease
29-05-2007, 00:16
' Usage of the STRING$ Keyword example
'
' Written by Abraxas


DIM sMainString as string value "HELLO WORLD"
DIM sStringExpression as string value "THINBASIC"
DIM sSTR AS STRING
DIM Count as DWORD Value 10
DIM n AS BYTE
DIM sMsg as string

sMsg += "sMainString = " & sMainString & $CRLF
sMsg += "sStringExpression = " & sStringExpression & $CRLF
sMsg += "Count = " & Count & $CRLF & $CRLF

' Take a letter from sStringExpression for the string fill character
FOR n = 1 to Len(sStringExpression)
sSTR = STRING$(Count, MID$(sStringExpression, n, 1)) ' Fill sSTR with 10 "T"'s
sMsg += "STRING$(Count, StringExpression) = " & sSTR & $CRLF
next
MsgBox 0, sMsg

ErosOlmi
29-05-2007, 04:07
Changed to:


Dim sStringExpression As String VALUE "THINBASIC"
Dim sSTR As String
Dim sChar As String
Dim Counter As DWORD
Dim sMsg As String

sMsg += "sStringExpression = " & sStringExpression & $CRLF & $CRLF

' Take a letter from sStringExpression for the string fill character
For Counter = 1 To Len(sStringExpression)
sChar = MID$(sStringExpression, Counter, 1)
sSTR = String$(Counter, sChar)
sMsg += "STRING$(" & Counter & ", " & sChar & ") = " & $Tab & sSTR & $CRLF
Next

MSGBOX 0, sMsg


Also improved STRING$ command. Next preview will have 2 syntaxes:


s = STRING$(Count, Code )
s = STRING$(Count, StringExpression)

STRING$ with a numeric argument returns a string of count copies of the character with the ASCII code of code, where code is between 0 and 255, inclusive.
STRING$ with a string argument returns a string of count copies of the first character in StringExpression.

Thanks
Eros