locked
How to read through a text string one character at a time? RRS feed

  • Question

  • Hello,  We're reading in a TXT file, then we are trying to scan through it from beginning to end, checking for (reading) through it one character at a time.  Can't find the right command to do it through the Text class.  Array does not seem to work for it either.  Any ideas?  Thanks!

    Saturday, January 22, 2011 5:37 PM

Answers

  • You can do this without a function in the text class. Try this:

    read = File.ReadContents("C:\test.txt")
    For i = 1 To Text.GetLength(read)
     character = Text.GetSubText(read, i, 1)
     TextWindow.WriteLine("Character " + i + ": " + character)
    EndFor


    ~~AirWaves!!~~
    • Proposed as answer by AirWaves Saturday, January 22, 2011 6:18 PM
    • Marked as answer by PeterDad Saturday, January 22, 2011 6:44 PM
    Saturday, January 22, 2011 6:09 PM

All replies

  • You can do this without a function in the text class. Try this:

    read = File.ReadContents("C:\test.txt")
    For i = 1 To Text.GetLength(read)
     character = Text.GetSubText(read, i, 1)
     TextWindow.WriteLine("Character " + i + ": " + character)
    EndFor


    ~~AirWaves!!~~
    • Proposed as answer by AirWaves Saturday, January 22, 2011 6:18 PM
    • Marked as answer by PeterDad Saturday, January 22, 2011 6:44 PM
    Saturday, January 22, 2011 6:09 PM
  • Ah, great. Looked at this command but interpreted its purpose incorrectly.  Works perfect, thanks!
    Saturday, January 22, 2011 6:45 PM