Skip to main content
August 26, 2009
Question

Removing spaces?

  • August 26, 2009
  • 1 reply
  • 623 views

Hi,

I am taking a text file and importing the data in to a SQL database.

One problem i have, spaces are also being imported into the field in the DB.

I have tried Ltrim, Rtrim, Trim, Replace " " but it still doesn't take the spaces off the data.

For example the data looks like so.

Smith                      !John                                        !

How do i remove the spaces?

Thanks.

This topic has been closed for replies.

1 reply

Inspiring
August 26, 2009

Use a while loop.  The logic is, while your string contains consecutive spaces, replace them with a single space.  You should be able to translate that to code.

Inspiring
August 26, 2009

or you can use a regular expression.  Here is an example that replaces consecutive pipes ( | ) with |null|.

Pattern.Pipes = "\|(?=\|)";  
/* The regular expression ("\|(?=\|)") says, find '|' followed by '|' but don't include the second 'I' in the replacement string.*/

/*
x.10 = ReReplace(string.6, Pattern.Pipes, "|null|", "all");

All you have to do is figure out how to do it with spaces.