Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Incrementing a string field
Message
From
19/12/2010 09:45:37
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01493214
Message ID:
01493285
Views:
73
Thanks, Viv, for pointing me in the right direction.
I finally got to that step this AM.
Other restraints in the system limit the number of versions to 10, starting with "A", so I just needed to increment it.

Here's another question:

This works
private void buttonCreatenewversion_Click(object sender, EventArgs e)
{
char c = Convert.ToChar(CurrentVersion);
c++;
string newversion = c.ToString();

} // key down


This gives me the existing version. Why is that??

private void buttonCreatenewversion_Click(object sender, EventArgs e)
{
char c = Convert.ToChar(CurrentVersion);
string newversion = c++.ToString();

} // key down

















>>I'm converting a VFP app that produces versions that start with "A" and proceed upward.
>>So, if the latest version is "C", the next version is "D", etc.
>>Developing the next version letter was easy in VFP, but all the answers I'm finding for C# seems needlessly cumbersome.
>>
>>What is the simplest way to put the next version letter in string NextVersion when the current version is in string CurrentVersion?
>
>You don't give much detail on the actual structure of the string. Maybe something like:

string CurrentVersion = "123D456";
>
> // One way
>char[] c = CurrentVersion.ToCharArray();
>c[3]++;
>string NextVersion = new string(c);
>













> //Another way
>char x = CurrentVersion[3];
>NextVersion = CurrentVersion.Replace(x, ++x);

but what should happen when you get to 'Z' ?

Maybe something like this (assuming only allowed 0-9 and A-Z):

static string IncrementString(string s)
{
char[] c = s.ToCharArray();
int i = c.Length - 1;
while (i>-1)
{
if (c[i] == 'Z') c[i--] = '0';
else
{
if (c[i] == '9') c[i] = 'A';
else c[i]++;
break;
}
}
return new string(c);
}

This will start over when it gets to 'ZZZZZn'
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform