Hi Jon,
You are a tremendous help to all who come to this board, and I am always in
awe of the completeness and clarity by which you communicate some very
technical things. That said, we do no student any favors by doing their
homework for them. We also make it difficult for teachers, since that
particular problem can never be used again for homework (thanks to the power
of Google). As the son of two college professors, I come to you as a
colleague to beg of you to set an excellent example for this board and to do
your best to avoid helping a student to cheat on their homework.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Niklas Engfelt wrote: Does anyone have a nice algorithm/method to increase all digits one
step, e.g. 123123 to 234234 and 4444 to 5555 and 999999 to 000000?
Well, it depends what you mean by "in one step". In one method call?
Very easily:
static string IncDigits(string text)
{
char[] chars = text.ToCharArray();
for (int i=0; i < chars.Length; i++)
{
char c = chars[i];
if (c >= '0' && c <='9')
{
// Not just c++ - wrap 9->0
c = (char)((((c-'0')+1)%10)+'0');
chars[i]=c;
}
}
return new string(chars);
}
Jon