01-07-2015 03:02 AM
I want to read one word at a time from a text file as it is done by "scanf &s" function in text based programme. It is not possible by " read from text" function. Suggest me function or method to solve this.
01-07-2015 03:12 AM - edited 01-07-2015 03:18 AM
The simplest way is to use the spreadsheet string to array function with the space character as the delimiter.
Note that this won't work unless there is a space character between the words - it won't work with line feeds / carriage returns between the words but you could always split the string into lines first. You may also want to trim whitespace to remove any other non-visible characters (e.g. tab, line feeds) from around the word.
If you need something more sophisticated that splits based on whitespace (e.g. tab, new line) then you'll probably need to do something with searching the string for these characters (e.g. using a regular expression) and then splitting them yourself into an array.
Of course...if you actually want to just read one word at a time from the file rather than just split the file into words (I assumed you meant this), you will need to read the file byte by byte using the low level file IO functions, build a buffer of the bytes and check the character you've read to see if it a space.
01-07-2015 03:23 AM
As mentioned, read the full file, replace all newlines with space, then Text to Array with \s as delimiter. Out comes an array of words. 😉
/Y