469,919 Members | 2,123 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,919 developers. It's quick & easy.

Removing excess white space

I am building up the validation expression for a RegularExpresionValidator
control by retreiving some values from a database and looping through the
DataTable to build and adding lots of | characters. Basically i want to
build up a string along the lines of ^102|103|104|105$ where the number are
coming from the data table. This is easy enough and works fine.
Unfortunately the data values from the database are padded out with loads of
spaces at the end which builds a string like ^102 |103 |104
|104 |$ which doesn't seem to work for the validation expression.
How do i remove the extraneus white space from the end of data before adding
it to the string variable. Bearing in mind that the data in the database is
not always the same length.
Apr 6 '06 #1
4 2287
DWS
Just an idea clickon
Trim the data in sql.
http://msdn2.microsoft.com/en-us/library/ms139947.aspx
select trim(name) from books

Good Luck
DWS
"clickon" wrote:
I am building up the validation expression for a RegularExpresionValidator
control by retreiving some values from a database and looping through the
DataTable to build and adding lots of | characters. Basically i want to
build up a string along the lines of ^102|103|104|105$ where the number are
coming from the data table. This is easy enough and works fine.
Unfortunately the data values from the database are padded out with loads of
spaces at the end which builds a string like ^102 |103 |104
|104 |$ which doesn't seem to work for the validation expression.
How do i remove the extraneus white space from the end of data before adding
it to the string variable. Bearing in mind that the data in the database is
not always the same length.

Apr 6 '06 #2
Unfortunately TRIM doesn't apear to be a TSQL function. At least it doesn't
work with SQL 2000, it just returns a "no such funtion as TRIM exception.

"DWS" wrote:
Just an idea clickon
Trim the data in sql.
http://msdn2.microsoft.com/en-us/library/ms139947.aspx
select trim(name) from books

Good Luck
DWS
"clickon" wrote:
I am building up the validation expression for a RegularExpresionValidator
control by retreiving some values from a database and looping through the
DataTable to build and adding lots of | characters. Basically i want to
build up a string along the lines of ^102|103|104|105$ where the number are
coming from the data table. This is easy enough and works fine.
Unfortunately the data values from the database are padded out with loads of
spaces at the end which builds a string like ^102 |103 |104
|104 |$ which doesn't seem to work for the validation expression.
How do i remove the extraneus white space from the end of data before adding
it to the string variable. Bearing in mind that the data in the database is
not always the same length.

Apr 6 '06 #3
Hi,

Once you've got the string from your DataTable, you can remove any
white space from the beginning and end using the Trim() method, e.g.:

regExp += "|" + myString.Trim(); // use a StringBuilder instead ;)

For more info on Trim(), see MSDN:
http://msdn2.microsoft.com/en-US/lib...s3(VS.80).aspx

Hope that helps,

Chris

Apr 6 '06 #4
Try RTRIM(str), this returns a string after removing all trailing
blanks.

SQL Server Books Online:
http://msdn.microsoft.com/library/de...ra-rz_6xm5.asp

Apr 6 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Malcolm Dew-Jones | last post: by
5 posts views Thread by Jonathan Daggar | last post: by
reply views Thread by Mark Moore | last post: by
2 posts views Thread by vbMark | last post: by
11 posts views Thread by gopal srinivasan | last post: by
2 posts views Thread by shagy | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.