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

Removing spaces?

New Here ,
Aug 26, 2009 Aug 26, 2009

Copy link to clipboard

Copied

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

Views

566

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Documentation