Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts

Saturday, March 31, 2012

Trim a DB field

I have this code and it works great for some of the numbers but not ther other.

<%# Mid(DataSet1.FieldValue("ListNum", Container).Trim(), 5,1) %> with a number of 675432 the result would be 3. With a number of 75432 the result would be 2. I need them always be in the 2 spot even if my field has a 7, 6, 5, or 4 digit numbers in it.

This is trimming the ListNum field in my database down to one number. When the database field is 6 numbers long it works perfectly. If the database number is 5 numbers long it selects the last number instead of the 2nd to the last number. Is there a way to get the trim command to count the numbers from the right and not the left. So the code would look something like this.

<%# Mid(DataSet1.FieldValue("ListNum", Container).Trim(), 2,1) %>

Thanks for any help.Try something like this:

Dim myString as string
myString = DataSet1.FieldValue("ListNum", Container).Trim()
myString = myString.Substring(myString.Length-2, 1)
The code is a section out of much more.. Here is the code all together.

<img src="http://pics.10026.com/?src=http://photos.neg.ctimls.com/neg/photos/small/<%# Mid(DataSet1.FieldValue("ListNum", Container).Trim(), 5,1) %>/<%# Right(DataSet1.FieldValue("ListNum", Container).Trim(), 1) %>/<%# DataSet1.FieldValue("ListNum", Container) %>a.jpg" width="100" alt="">

Because it is a piece of a code that is why I can't use something like that. Also there are many of these for one page on the site so I have to keep it as simple as possible.

Thanks

Trim trailing 0 from decimal place of number

Hi,

I am having difficulty trimming any traling 0's from my decimal numbers.
I store then in the database to 2 decimal places.
This means that when they come back to my application they still diply with
all the decimal places

eg

10.00 displays as 10.00
10.10 displays as 10.10

what I would like to achieve is the following

10.00 displays as 10
10.10 displays as 10.1

many thanks in advance

cheers

martin.string.Format("{0}",10);
string.Format("{0}",10.10);

should do the trick. Actually the above behavior should be the default
behavior...

+++ Rick --

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
-----------
Making waves on the Web

"martin" <Stuart_REMOVE_36@.yahoo.com> wrote in message
news:OXKXwadbEHA.2216@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I am having difficulty trimming any traling 0's from my decimal numbers.
> I store then in the database to 2 decimal places.
> This means that when they come back to my application they still diply
with
> all the decimal places
> eg
> 10.00 displays as 10.00
> 10.10 displays as 10.10
> what I would like to achieve is the following
> 10.00 displays as 10
> 10.10 displays as 10.1
> many thanks in advance
> cheers
> martin.

Trim trailing 0 from decimal place of number

Hi,
I am having difficulty trimming any traling 0's from my decimal numbers.
I store then in the database to 2 decimal places.
This means that when they come back to my application they still diply with
all the decimal places
eg
10.00 displays as 10.00
10.10 displays as 10.10
what I would like to achieve is the following
10.00 displays as 10
10.10 displays as 10.1
many thanks in advance
cheers
martin.string.Format("{0}",10);
string.Format("{0}",10.10);
should do the trick. Actually the above behavior should be the default
behavior...
+++ Rick --
Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
--
Making waves on the Web
"martin" <Stuart_REMOVE_36@.yahoo.com> wrote in message
news:OXKXwadbEHA.2216@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I am having difficulty trimming any traling 0's from my decimal numbers.
> I store then in the database to 2 decimal places.
> This means that when they come back to my application they still diply
with
> all the decimal places
> eg
> 10.00 displays as 10.00
> 10.10 displays as 10.10
> what I would like to achieve is the following
> 10.00 displays as 10
> 10.10 displays as 10.1
> many thanks in advance
> cheers
> martin.
>

Trimming Text for a certian charachter or word

I have a database with unique ID numbers. Each id number has images connected to it.

For Example:

www.mysite.com/images/1/4/778814.jpg

www.mysite.com/images/"T"/"U"IDNUMBer.jpg

As you will see the "T" folder comes from the tens spont of the id number. The "U" folder come from the units spot and the image name is the ID and then I have to add jpg. Now i would never create a database like this but that is what this company is supplying me. My question is how to make asp split the id number up to use in other locations.



Thanks

RustyI can think of 2 options. See which is best for you based on the datatype of the idnumber.
a) You can work with strings and use
Dim unit, tens as String
unit = idnumber.ToString().Chars(idnumber.ToString().Length -1) 'to get units character
tens = idnumber.ToString().Chars(idnumber.ToString().Length -2) 'to get the tens character
b) Work with integers and use mathematical operators Eg:
Dim idnumber As Integer
idnumber = 456789
Dim unit, tens As Integer
unit = idnumber Mod 10 ' Returns 9
tens = (idnumber Mod 100) \ 10 ' Returns 8
Use the Split method to split the string by "/" and then you can use each of the elements of the created Array to grab the numbers.

string fullUrl = "www.mysite.com/images/1/4/778814.jpg";
string[] splitParams = fullUrl.Split('/');

splitParams[0] is "www.mysite.com"
splitParams[1] is "images"
splitParams[2] is "1"
splitParams[3] is "4"
splitParams[4] is "778814.jpg"

HTH

DJ