Results 1 to 2 of 2

Thread: Usage of the STRING$ keyword

  1. #1
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Usage of the STRING$ keyword

    [code=thinbasic]
    ' 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
    [/code]
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Usage of the STRING$ keyword

    Changed to:

    [code=thinbasic]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
    [/code]

    Also improved STRING$ command. Next preview will have 2 syntaxes:
    [code=thinbasic]
    s = STRING$(Count, Code )
    s = STRING$(Count, StringExpression)
    [/code]
    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •