Go to: Synopsis. Return value. Related. MEL examples.
fgetword
int [string]
fgetword is NOT undoable, NOT queryable, and NOT editable.
Returns the next word (string of characters separated by white space characters) or nothing at end of file. A second argument may be passed to the fgetword command to specify separators to use instead of the default white space sparators. Characters in the separator string are used to determine word boundaries. The each character in the separator string is treated as an individual separator.string | Next word |
// Make a sample file to use as a test example // $exampleFileName = ( `internalVar -userTmpDir` + "example.tmp" ); $fileId=`fopen $exampleFileName "w"`; fprint $fileId "Hello there\nMEL-Developer-+Using+fgetword\n"; fclose $fileId; // Now read it back one word at a time // $fileId=`fopen $exampleFileName "r"`; string $nextWord = `fgetword $fileId`; while ( size( $nextWord ) > 0 ) { print ( $nextWord + "\n" ); $nextWord = `fgetword $fileId`; } fclose $fileId; // This will print: // Hello // there // MEL-Developer-+Using+fgetword // Read it back again using "+" and "-" as separators // $fileId=`fopen $exampleFileName "r"`; string $nextWord = `fgetword $fileId "+-"`; while ( size( $nextWord ) > 0 ) { print ( $nextWord + "\n" ); $nextWord = `fgetword $fileId "+-"`; } fclose $fileId; // This will print: // Hello there // MEL // Developer // Using // fgetword