[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1582
  • Last Modified:

Need to trim off last two characters on the right

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
foreverdita
Asked:
foreverdita
1 Solution
 
foreverditaAuthor Commented:
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
 
mantaraeCommented:
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
 
peh803Commented:
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
 
ColosseoCommented:
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
 
peh803Commented:
yes scott, you're exactly right, thank you for that!

peh803
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now