It's often a good idea to clean up any potential leading and trailing white spaces in your data set early on in your process.
The Data Quality indicators in the Data Viewer provide you with information on potential issues with white space characters in string fields in your data.
Trim Fields node
A quick way to trim leading and trailing white spaces across ALL your fields in one step is to connect your dataset to a Trim Fields node, which you can find under Aggregation and Transformation.
You don't need to change any of the properties of the Trim Fields node as the default configuration will work.
Give it a try by simply connecting a Trim Fields node to a Create Data node - no need to change any other properties for either node:
The Trim node allows you to specify a list of fields that should be excluded (default) or included when the Trim node is run. You can use the context menu for the FieldList property to insert input field names (you will still need to type the comma separators).
You can read more about the Trim Fields node in the Help: Node help > Aggregation and Transformation > Trim Fields
Python Strip function
If you want to trim white space characters from your data as part of an wider transformation process, you can instead use the Python strip() function within the Transform node.
For example, to remove extraneous whitespace from an input field 'myInput', you might include the following in a Transform node:
# Copy the metadata for all input fields to the output record specification
out1 += in1
# Specify the new field to contain the trimmed values
out1.myInputTrimmed = unicode
# Copy all input field values to the output record
out1 += in1
# Assign the trimmed string value to the new field
out1.myInputTrimmed = fields['myInput'].strip()
Note that you will need to either ensure there are no Null values in the input field data (e.g. by using a Filter or Split node upstream of the Transform node) or handle the Null values within the ProcessRecords script e.g. using conditional logic such as:
out1.myInputTrimmed = Null if fields['junk'] is Null else fields['junk'].strip()
You can read more about the new Transform node in the Help: