go to previous page   go to home page   go to next page

Answer:

"      ".trim()

This returns a (pointer to) a null string.


Trim Transducer

Here is a finite-state transducer with some labels left blank. The transducer must deal with input strings such as

"  abc    def   " 

which have white space in the middle. But without looking ahead, the transducer can't tell if the current character is an internal space (such as the one after c) or an outside space (such as the one after f).

To deal with that problem, the transducer copies possible internal spaces to a buffer. This is done in the transition between state 0 and state 1, and also in the transition between state 2 and itself. When an ordinary character is encountered in state 2, the spaces in the buffer and the character are appended to the output string. If no ordinary character is encountered, the transducer remains in a final state and the buffer is discarded.

     
  transition arrow transition arrow  
transition arrow state 0 transition arrow state 1  
    white : copy to
buffer
transition arrow ord : append
buffer+ord
to output
      state 2  
    white : copy to
buffer
transition arrow  

A few transitions remain unlabeled. Mentally label them

input character(s) : output characters(s)

Use white to mean a white space character and ord to mean an ordinary character. To indicate no output character use "epsilon".


QUESTION 9:

What will be the output string for this input string:

"    Friends,   Romans,   countrymen   "