C# - 178 169 157 characters
This assumes that numbers like 999 are allowed to overflow to 000 and that -+,.E are not part of a number.
class T{static void Main(){var a="".ToCharArray();for(int b=1,c,i=a.Length;i-->0;b=48>c|c>57?7:b>0?c>56?a[i]='0':++a[i]*0:b)c=a[i];System.Console.Write(a);}}
Better readable form:
class T
{
static void Main()
{
var a="7teststring134this 123test string59 100".ToCharArray();
for (int b=3, c, i=a.Length; i-->0;
b=48>c|c>57
?7
:b>2
?c>56?a[i]='0':++a[i]*0
:b
) c=a[i];
System.Console.Write(a);
System.Console.ReadKey();
}
}
I'm new here, never tried code golf before, just gave it a try :)
I wonder if anyone has ideas to get it even shorter...
To participate with C# it would be nice if we could omit all the necessary framework around the actual code - then this would only have 82 chars, and that without calling any powerful system functions.
The same with pointers (182 chars):
class T
{
unsafe static void Main()
{
char[] a="7teststring134this 123test string59 100".ToCharArray();
int b=3;
fixed (char* s=&a[0])
for (var p=s+a.Length; p-->s; )
b=*p<48|*p>57
?7
:b>2
?*p>56?*p='0':++*p*0
:b;
System.Console.Write(a);
System.Console.ReadKey();
}
}
Now without overflowing, this correctly handles the 999 case (223 chars):
class T
{
static void Main()
{
var s=new System.Text.StringBuilder("9999teststring134this 123test string99 100");
for (int b=3, c, i=s.Length; i-->0; )
{
c=s[i];
b=48>c|c>57
?b>8?8:7
:b>2
?c>56?c-(s[i]='0'):++s[i]*0
:b;
if (b>8&i<1|b==8) s.Insert(i+9-b, '1');
}
System.Console.Write(s);
System.Console.ReadKey();
}
}
Another different older one, it reads from standard input and uses recursion:
namespace System {
using C=Console;
class T {
class t {
byte b=1;
string s="";
void R() {
var c=C.Read();
if (c>31) {
R();
if (48>c|c>57) b=1;
else if (b==1) c=c==57?48:++c*b--;
s=(char)c+s;
}
}
public t() {
R();
C.Write(s);
}
}
static void Main() {
new t();
C.ReadKey();
}
}
}
Note: Console.ReadKey();
and the string itself should not be counted.
I improved this already multiple times, see comments. There is still room for more improvements, I would say :)
And sorry for the length, but I think the different versions are interesting enough to keep them...