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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP 2.00 1

Status
Not open for further replies.

SteveD73

Programmer
Jan 5, 2001
109
0
0
GB
Hi

I have a string which has the following format:

34-23

The problem is I want to add 1 to each of the digits, except for the hyphen, and then display the result on the screen. And another problem is that im using ASP Version 2.0.

The code I've tried so far is:

Dim byteChar
Dim paramString

' get the string
paramString = Request("editCode")

' process the first half of the string
For i=0 to 2
' can't use Mid because this is only ASP V2.0
byteChar = right(left(paramString, i), 1)

' add 1 to the character
byteChar = byteChar + 1

' display the result
Response.Write byteChar
Next

Response.Write "-"

' process the second half of the string
For i=3 to 5
' can't use Mid because this is only ASP V2.0
byteChar = right(left(paramString, i), 1)

' add 1 to the character
byteChar = byteChar + 1

' display the result
Response.Write byteChar
Next

The trouble is the above does not work.

Thanks for any help.
 
Try this:

nDash = Instr(sStr,"-")
nNum1 = Left(sStr,nDash-1) & "0"
nNum2 = Right(sStr,len(sStr)-nDash) & "0"

 
If it is always going to be 5 characters (##-##) then why not just do something like:
[COLOR=#80000]<%
Dim outputString
outputString = cInt(Left(paramString,2)) + 11
outputString = outputString & &quot;-&quot;
outputString = outputString & cInt(Right(paramstring,2)) + 11

Response.Write &quot;Incremented string is &quot; & outputString
%>
[/color]

That way you increment the appropriate characters faster.
If it is possible to have more than two characters on either side, you could get the left and right dynamically dpeenat on the location of the hyphen in the string and then do a for loop from 0 to len of the subsection-1 and add 10^(loop counter) or build a string of 1's and convert to int:
[COLOR=#80000]<%
'pretend paramstring has unknown number of numbers on either side:

Dim lside, rside
lside = Left(paramString,InStr(paramString,&quot;-&quot;))
rside = Right(paramString,len(paramString) - InStr(paramString,&quot;-&quot;))

Dim i, additive
additive = 0
For i = 1 to len(lside)
additive = additive * 10 + 1
Next
lside = cLng(lside) + additive

additive = 0
For i = 1 to len(rside)
additive = additive * 10 + 1
Next
rside = cLng(rside) + additive

Dim outputString
outputString = lside & &quot;-&quot; & rside
Response.Write &quot;The incremented string is: &quot; & outputString
%>
[/color]


Let me know if there is any issues with this running under 2.0, I've used 3.0 for long enough that I can't remember what was supported,
-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
You could try
aryNumbers = Split(OldNumString, &quot;-&quot;)
NewNumString = aryNumners(0) + 1 & &quot;-&quot; & aryNumbers(1) + 1



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top