473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Incrementing a Letter

Hi,

I saw the thread here: http://www.thescripts.com/forum/thread255915.html and I am currently working on building on it.

Well, what I need is something that takes in a string and increments it by one.

eg. 0 becomes 1
1 becomes 2
9 becomes a
a becomes b
z becomes 00
09 becomes 0a
0z becomes 10
9z becomes aa
zz becomes 000
and so on and so forth

Heres what I've managed to do so far, but it doesnt seem to be working.
Expand|Select|Wrap|Line Numbers
  1.         private string IncrementLetter(string c)
  2.         {
  3.             string[] iArray; 
  4.             for (int x = 0; x < c.Length; x++)
  5.             {
  6.                 iArray[x] = (char)((int)c.Substring(x, 1));
  7.                 if (iArray[x] == 57)
  8.                 {
  9.                     iArray[x] == 97;
  10.                 } else if (iArray[x] == 122)
  11.                 {
  12.                     iArray[x] == 48;
  13.                     iArray[x + 1] == 48;
  14.                 } else {
  15.                     iArray[x]++;
  16.                 }
  17.             }
  18.             return iArray.ToString;
  19.         }   
Errors:
Error 2 Cannot convert method group 'ToCharArray' to non-delegate type 'int'. Did you intend to invoke the method? D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 45 29 ConsoleApplication1
Error 3 Operator '==' cannot be applied to operands of type 'string' and 'int' D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 46 21 ConsoleApplication1
Error 4 Only assignment, call, increment, decrement, and new object expressions can be used as a statement D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 48 21 ConsoleApplication1
Error 5 Operator '==' cannot be applied to operands of type 'string' and 'int' D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 48 21 ConsoleApplication1
Error 6 Operator '==' cannot be applied to operands of type 'string' and 'int' D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 49 28 ConsoleApplication1
Error 7 Only assignment, call, increment, decrement, and new object expressions can be used as a statement D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 51 21 ConsoleApplication1
Error 8 Operator '==' cannot be applied to operands of type 'string' and 'int' D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 51 21 ConsoleApplication1
Error 9 Only assignment, call, increment, decrement, and new object expressions can be used as a statement D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 52 21 ConsoleApplication1
Error 10 Operator '==' cannot be applied to operands of type 'string' and 'int' D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 52 21 ConsoleApplication1
Error 11 Operator '++' cannot be applied to operand of type 'string' D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 54 21 ConsoleApplication1
Error 12 Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method? D:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 57 20 ConsoleApplication1
Thanks in advance!
Dec 4 '06 #1
1 3632
kenobewan
4,871 Expert 4TB
You could look at reverse engineering this problem. How about taking the value of the string and using a try catch statement to convert to integer? Then you can treat the value as a string or an integer depending on the value.

This takes advantage of any conversion problems. What do you think?
Dec 6 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: trickydicky | last post by:
Does anyone know of an easy way to increment a string by one letter at a time? What I want to be able to do is set a variable with the value "A" and then be able to use a For loop to make it...
11
by: John Velman | last post by:
I've used perl for a lot of 'throw away' scripts; I like Python better in principle, from reading about it, but it was always easier to just use perl rather than learn python. Now I'm writing a...
9
by: Michael | last post by:
Hi, I've got a string s, and i want to shift all the letters up by one, eg a->b, b->c ........ z->a In c++ i can do this quite simply with if(C == 'z') C='a'; else C++; but i can't work out...
3
by: Mothra | last post by:
Here's what I'm trying to do (kill off old Unix logins): --------------------- $i=0; while (<$who>) { chomp($_); my @line = split(/\s+/, $_); # Split it into an array next unless ($line...
12
by: Alan J. Flavell | last post by:
OK, today's email brought a comment from a reader, pointing out something that I'd long since noticed myself but hadn't done anything about it. On my pages, I've got a first-letter style on...
1
by: mr_burns | last post by:
hi, i am trying to use a function that will write html into empty <span> tags. the <span> tags will all be numbered incrementally and written to using the same function each time. below is my...
2
by: brian | last post by:
Hi, before coming to .NET, I utilized regular expressions mostly in JScript / JavaScript and also in my favorite text editor: TextPad (www.textpad.com) I don't know about JScript/JavaScript, but...
10
by: Antanas | last post by:
The problem is that when AddID is used multiple times in the same select statement, it returns the same value in all places. How could I force function AddID to increment OBJECTID sequence? Here...
8
by: JD via AccessMonster.com | last post by:
I am trying to create a field where the primary key field will produce JDP- 001; where the three letters come from the first name, middle intial and last name of my table. I want to auto increment...
9
by: subramanian100in | last post by:
The following portion is from c-faq.com - comp.lang.c FAQ list · Question 6.13 int a1 = {0, 1, 2}; int a2 = {{3, 4, 5}, {6, 7, 8}}; int *ip; /* pointer to int */ int (*ap); /* pointer to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.