How to Trim values in the graph

Does anyone have example of how to use Trim function in Reformat graph.
i.e
I am trying to read from database and write to a flatfile. Let’s say there is only one field “Name”, which as trailing space. How can I use trim fucntion to remove all spaces before writing in the flat file.

function transform(){
$Name:=trim($Name);
}

or

function transform(){
$Name:=iif(isnull($Name),null,trim($Name));
}