Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need to trim off last two characters on the right

Posted on 2004-10-21
5
Medium Priority
?
1,578 Views
Last Modified: 2008-06-29
For example - I have a sku called 1102301 and I need to return the value of 11023 without the 01.  Is there a way to do this in asp?  I tried using the rtrim but I keep getting errors.

Thanks!

0
Comment
Question by:foreverdita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Author Comment

by:foreverdita
ID: 12372455
I should also add that the skus are all different lengths - example:

1102301
134202
154231109

(where I still need to trim the last two numbers from the end)

0
 
LVL 7

Accepted Solution

by:
mantarae earned 2000 total points
ID: 12372483
rtrim is to remove spaces.

you probably would want to use left

<% =Left("11023", len(yourSKU) - 2) %>

If you use right, you would only get the 2 numbers you're trying to get rid of.
0
 
LVL 19

Expert Comment

by:peh803
ID: 12373066
This is just an add on to mantarae's already great post, so please; give credit where credit is due (i.e., I'm NOT trying to steal anyone's points)!

I just wrote a function (today!) to do this for me....Take a look, you may find it useful.

Regards,
peh803

<%
function trimRightChars(sStr, lNumChars)
  Dim sRetStr
  sRetStr = left(sStr, (len(sStr)-lNumChars))
  trimLastChar = sRetStr
end function
%>

So, to trim off the right-most two characters, you'd do this:
<%
Dim sString
sString = "1234567890"
response.write "Untrimmed: " & sString & "<BR>"
response.write "trim 1: " & trimRightChars(sString,1) & "<BR>"
response.write "trim 2: " & trimRightChars(sString,2) & "<BR>"
response.write "trim 3: " & trimRightChars(sString,3) & "<BR>"
response.write "trim 4: " & trimRightChars(sString,4) & "<BR>"
%>

I think if you run this example, you'll see how it works!

Regards,
peh803
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 12373295
Hi

i'm not trying to steal anyones points either :)

but i think pehs function has a typo and should be

<%
function trimRightChars(sStr, lNumChars)
  Dim sRetStr
  sRetStr = left(sStr, (len(sStr)-lNumChars))
  trimRightChars= sRetStr
end function
%>

Cheers

Scott
0
 
LVL 19

Expert Comment

by:peh803
ID: 12373336
yes scott, you're exactly right, thank you for that!

peh803
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question