String subtraction.... ABCD - 1 = ABCC ????? How ?

# Thread: String subtraction.... ABCD - 1 = ABCC ????? How ?

1. Member
Join Date
Dec 1969
Posts
31

## String subtraction.... ABCD - 1 = ABCC ????? How ?

Hello, is it possible to do string subtraction / addition like it is in the C language ? What I want to do is have a string : say ABCD, and then subtract 1 from it, to get ABCC....If you get what i mean...<BR><BR>Is this possible without doing some sort of complex array thing ?<BR><BR>Thanks,<BR>Adam

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## And what is ABCA - 1???

What happens when you get to A on that last character? Where do you go from there?<BR><BR>Toss away the last character and start working on the next?<BR><BR>ABCA - 1 ==&#062;&#062; ABB ???<BR><BR>or<BR><BR>ABCA - 1 ==&#062;&#062; ABBZ ???<BR><BR>And what happens when you do<BR><BR>AAAA - 1 ????<BR><BR>You tell me all that, I&#039;ll tell you what to do.<BR><BR>

3. Member
Join Date
Dec 1969
Posts
31

## RE: And what is ABCA - 1???

ABCA - 1 = ABBZ.....<BR>in the meantime ive written my own script that does it all manually, but i only needed it too work with a 2 length string that can be either numbers or letters....<BR><BR>thanks anyway,<BR>adam

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## I have no idea...

...what you meant by a "script that does it all manually" or what a "2 length" string is.<BR><BR>And you still didn&#039;t say what to do with AAAA - 1<BR><BR>But here we go:<BR><BR>************************<BR>&#060;HTML& #062;&#060;BODY&#062;<BR><BR>&#060;%<BR>Function SubtractOne( str )<BR> dim p, notLast, last<BR> p = Len(str) &#039; look at last character<BR> If p = 0 Then<BR> Response.Write "Can&#039;t subtract from that!"<BR> Response.End<BR> End If<BR> str = UCase( str ) &#039; just in case<BR> last = Right( str, 1 ) &#039; get last character<BR> notLast = Left( str, p-1 )<BR> If last = "A" Then<BR> SubtractOne = SubtractOne( Left( str, p-1 ) ) & "Z"<BR> Else<BR> SubtractOne = notLast & Chr( Asc(last)-1 )<BR> End If<BR><BR>End Function<BR><BR>test = Request("test")<BR>If test = "" Then test = "ABCD"<BR><BR>For i = 1 to 10<BR> minusOne = SubtractOne( test )<BR> Response.Write test & " minus one is " & minusOne & "&#060;br/&#062;" & vbNewLine<BR> test = minusOne<BR>Next<BR>%&#062;<BR>&#060;HR&#062;<BR>& #060;FORM&#062;<BR>Enter a string to test: <BR>&#060;INPUT Name="Test" Value="AABA"&#062;<BR>&#060;P&#062;<BR>&#060;INPUT Type=Submit Value="Try that..."&#062;<BR>&#060;/FORM&#062;<BR><BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•