PDA

View Full Version : trailing spaces in data


rpaterick
May 18th, 2009, 02:51 PM
When importing a .csv file and the client has trailing spaces in the data that should not be there. Is there a specific way to import the .csv file or rules to apply?
I tried the Users Manual and couldn't figure-out how to eliminate trailing spaces.

Thanks,
Ryan:o

DSweet
May 19th, 2009, 05:01 AM
Ryan,

There are a number of commands that will let you remove trailing spaces and/or leading spaces in data fields. They are called "trim" commands.

LTrim(Field"yourfield") will remove leading spaces (extra spaces to the left or in the beginning of the data field you specify).

RTrim(Field"yourfield") will remove trailing spaces (extra spaces to the right or after the data field you specify).

Trim(Field"yourfield") will remove both trailing and leading spaces in your data field.

You can even use "regular expressions" to remove the possibility of extra spaces within the data field string itself.

Good Luck.

rpaterick
May 19th, 2009, 08:44 AM
You can even use "regular expressions" to remove the possibility of extra spaces within the data field string itself.

Good Luck.

DSweet, thanks for the suggestions. Because the data is Upper-Case, I applied the "Proper-Case" to the field and that took care of the trailing spaces also, weird.:cool:

Thanks,
Ryan

rpaterick
May 19th, 2009, 03:51 PM
Ryan,
There are a number of commands that will let you remove trailing spaces and/or leading spaces in data fields. They are called "trim" commands.

DSweet, I'm putting a comma after the Field City and I'm getting one blank space added. I have Proper Casing applied to the field but how do I apply the RTrim code properly to it?

ex: Munro , BUENOS AIRES 1605ank
extra space after the word Munro.

Code below of the "City" column.

Thanks,
Ryan

Var1="City";
CaseSelection="propercase";



if(CaseSelection == "allcaps")
return ToUpper(Field(Var1));

if(CaseSelection == "smallcaps")
return "<smallcap>" + Field(Var1) + "</smallcap>";

if(CaseSelection == "propercase")
return ToTitleCase(Field(Var1));

if(CaseSelection == "lowercase")
return ToLower(Field(Var1));

DSweet
May 20th, 2009, 05:11 AM
Ryan,

Functions can be nested within one another, but I normally put any trim function as the outside function like so...

if (CaseSelection == "propercase")
....return RTrim(ToTitleCase(Field(Var1)));

This way I am sure that whether or not the inner function(s) add spaces to the field, I know that any extra leading or trailing spaces will be removed before the rule returns its value.

Good luck.