2 Replies Latest reply on Aug 26, 2009 11:29 AM by Dan Bracuk

    Removing spaces?

    craig_uk

      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.

        • 1. Re: Removing spaces?
          Dan Bracuk Level 5

          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.

          • 2. Re: Removing spaces?
            Dan Bracuk Level 5

            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.