Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to Incrementing Strings..... 2

Status
Not open for further replies.

Edcrosbys

ISP
Apr 26, 1999
112
US
I have a alphanumeric string (1234-AB) and wanted to know if anyone knows of a was to increment the last letter from
either Javascript or VBScript.

I could strip off the last character and do a long case statement, but I wasn't sure if there was an easier way.

Thanks Alot!
EdCrosbys
 
Hmm... Convert to numeric form, increment, convert back, append.

Okay. How are you talking about converting it? I did a long case statement, and set the variable depending on what the case was. i.e.

Select Case Letter
Case a
nextletter=b
Case b
nextletter=c

etc, etc. What's the conversion you are talking about??? Thanks Alot!!
EdCrosbys
 
I hope the following code will be helpful.
In my computer, it works.

<%
Option Explicit
dim strTest
dim strTemp, strSwap
strTest = &quot;1234-AB&quot;
strTemp = Left(strTest,Len(strTest) - 1)
strSwap = Right(strTest,1)
output(&quot;Original Data<br>&quot;)
outPut(strTest)
outPut(&quot;<br>&quot;)
outPut(strSwap)
outPut(&quot;<br>&quot;)
outPut(strTemp)
outPut(&quot;<br>&quot;)
dim intTemp
intTemp = Asc(strSwap)
intTemp = intTemp + 1
strTemp = strTemp + Chr(intTemp)
outPut(&quot;Data you needed&quot;)
outPut(&quot;<br>&quot;)
outPut(strTemp)
Function outPut(var)
Response.Write(var)
End Function
%>

You should do some more... For instance, the coversion of 'a' and 'Z'
 
ccat answered your question well:

intTemp = Asc(strSwap)
intTemp = intTemp + 1
strTemp = strTemp + Chr(intTemp)

The asc and chr functions are what you need.

Every letter of the alphabet has an ansi value which is numeric. That can be incremented and converted back. The numbers for capital A and lowercase a are different, 65 & 97, so you might want to pay attention to that. Jonathan Galpin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top