Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Removing spaces?

Guest
Aug 26, 2009 Aug 26, 2009

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.

TOPICS
Advanced techniques
595
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 26, 2009 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 26, 2009 Aug 26, 2009
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources