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.
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.
Copy link to clipboard
Copied
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.