PDA

View Full Version : Removing leading Zero


Abd
08-05-2003, 02:42 PM
Hi All,

pls how will I remove a leading ZERO from a textfield before inserting to Database.

Leading ZERO NOT leading space.

Thanks

bostjank
08-05-2003, 03:11 PM
You can use

sTextWithoutZero = Right(sText, Len(sText) - 1)

You may also check if there is a leading zero.


Bostjan

whammy
08-06-2003, 08:45 PM
While Left(yourString,1) = "0" AND yourString <> ""
yourString = Right(yourString,Len(YourString)-1)
Wend

Abd
08-08-2003, 09:58 AM
I am working with ASP and NOT PHP, so please I want help in ASP

bostjank
08-08-2003, 12:16 PM
All the answers were for ASP.

whammy
08-08-2003, 03:12 PM
:rolleyes:

That was ASP, all right (VBScript, the default language). What version of ASP are you using :confused:

whammy
08-08-2003, 03:15 PM
P.S. Here's the same functionality put into a function (along with an example of how to use it):

<%
Function RemoveLeadingZeroes(ByVal str)
Dim tempStr
tempStr = str
While Left(tempStr,1) = "0" AND tempStr <> ""
tempStr = Right(tempStr,Len(tempStr)-1)
Wend
RemoveLeadingZeroes = tempStr
End Function


yourString = "00000000000000000334005"
Response.Write(RemoveLeadingZeroes(yourString))
%>

Morgoth
08-08-2003, 06:17 PM
While Left(yourString,1) = "0" AND yourString <> ""
yourString = Right(yourString,Len(YourString)-1)
Wend


Why use while? "If" statements are just as good, if not faster. Aren't they, whammy?


If Left(Trim(StrText1, 1)) = "0" AND Trim(StrText1) <> "" Then
StrText1 = Right(StrText1, Len(StrText1) - 1)
End If


I don't know what his field looks like, but if the user can type it in, there might be spaces instead of anything. I like to use Trim().

whammy
08-08-2003, 07:57 PM
What if you have more than one leading zero? Then your "If" won't work - but "While" will. ;)

Get it?

As far as using Trim, you can always do this, too:

Response.Write(Trim(RemoveLeadingZeroes(yourString)))

:D

Morgoth
08-08-2003, 09:19 PM
I guess While would work for that, but a do loop works too ;)

whammy
08-08-2003, 11:15 PM
Yeah... they're pretty much interchangeable in most cases (such as this one). But "Do While Loop" is two more letters then "While Wend".

;)

Morgoth
08-08-2003, 11:54 PM
Yep, and that is why I am not using it...
;)

Thanks for the info.