Small Basic

The Official Blog of Small Basic

Small Basic: How to Convert Multi-Line Text into an Array of Lines - Featured Article

Small Basic: How to Convert Multi-Line Text into an Array of Lines - Featured Article

Rate This
  • Comments 2

Today's featured TechNet Wiki article is from Nonki Takahashi

Small Basic: How to Convert Multi-Line Text into Array of Lines

 

Small Basic can get multi-line text into a variable from multi-line input text box with Controls.GetTextBoxText() or from text file with File.ReadContents().
The following sample code shows how to convert a multi-line text into an array of lines.

CRLF Text.GetCharacter(13Text.GetCharacter(10)
GraphicsWindow.BackgroundColor "LightGray"
GraphicsWindow.BrushColor "Black"
gw GraphicsWindow.Width
gh GraphicsWindow.Height
tb Controls.AddMultiLineTextBox(00)
Controls.SetSize(tbgwgh 30)
Controls.AddButton("Enter"gw 50gh 30)
Controls.ButtonClicked OnButtonClicked
Sub OnButtonClicked
  buf Controls.GetTextBoxText(tb)
  ConvertTextToLines()
  ShowLines()
EndSub
Sub ConvertTextToLines
  len Text.GetLength(buf)
  nLines 0
  ptr 1
  While ptr <len
    eol Text.GetIndexOf(Text.GetSubTextToEnd(bufptr)CRLF)
    If eol Then ' eol not found
      nLines nLines 1
      lines[nLinesText.GetSubTextToEnd(bufptr)
      ptr len 1
    Else ' eol found
      nLines nLines 1
      lines[nLinesText.GetSubText(bufptreol 1)
      ptr ptr eol 1
    EndIf    
  EndWhile
EndSub
Sub ShowLines
  For To nLines
    TextWindow.WriteLine("lines[" "]: " lines[i])
  EndFor
EndSub
  
  

Read the latest version of this TechNet Wiki article with an improved code block snippet here: 

Small Basic: How to Convert Multi-Line Text into Array of Lines

  
 
Thanks again to Nonki for this great contribution! 
 
   - Ninja Ed
Blog - Comment List MSDN TechNet
  • Loading...
Leave a Comment
  • Please add 1 and 3 and type the answer here:
  • Post