有点overkill了吧 using unsafe code for this problem ... :)
statement
p*p
4 楼
i see, 那么我现在的问题是整个字符串的每个字符都要移动3袼,是不是这样就可以了 string tmp=Console.Readline(); for(i=0;i{ tmp[i]=(char)(tmp[i]+3); } 3x
【在 L*******r 的大作中提到】 : just do explicit cast: : char tmp = 'a'; : tmp = (char)(tmp + 3); : Console.WriteLine(tmp); : it works.
L*r
5 楼
your idea is ok. but: 1. you can't do tmp[i] = ....., that one is read only. If you know java, you must know string is inmutable. 2. don't forget the declaration of "i". int i . I know that's trivial :)
【在 p*******p 的大作中提到】 : i see, 那么我现在的问题是整个字符串的每个字符都要移动3袼,是不是这样就可以了 : string tmp=Console.Readline(); : for(i=0;i: { : tmp[i]=(char)(tmp[i]+3); : } : 3x
L*r
6 楼
So you should create a new string, append every "result" character to that string. then do tmp = tmp1. hehe. your old string will be recycled by the system later.
了
【在 L*******r 的大作中提到】 : your idea is ok. : but: : 1. you can't do tmp[i] = ....., that one is read only. : If you know java, you must know string is inmutable. : 2. don't forget the declaration of "i". int i . I know that's trivial :)
【在 L*******r 的大作中提到】 : So you should create a new string, append every "result" character to that : string. then do tmp = tmp1. hehe. your old string will be recycled by the : system later. : : 了
hehe, just the immutable and mutable issue. Very common issue. When I was teaching Java for cs undergraduate, they always asked those kind of "string" questions. :) Anyway, you have stringbuffer in Java. I talked about stringbuilder, whcih is "stringbuffer" equivalent in C#, in my recent post. :)
that the
【在 w****n 的大作中提到】 : ft, is this the beauty of o-o stuff ? :)
p*p
10 楼
thanks, got u, :)
【在 L*******r 的大作中提到】 : hehe, just the immutable and mutable issue. Very common issue. : When I was teaching Java for cs undergraduate, they always asked those kind of : "string" questions. :) : Anyway, you have stringbuffer in Java. : I talked about stringbuilder, whcih is "stringbuffer" equivalent in C#, in my : recent post. :) : : that : the
w*n
11 楼
name is too long, hehe why not 'strbuf' and 'strbuilder' hehe
【在 L*******r 的大作中提到】 : hehe, just the immutable and mutable issue. Very common issue. : When I was teaching Java for cs undergraduate, they always asked those kind of : "string" questions. :) : Anyway, you have stringbuffer in Java. : I talked about stringbuilder, whcih is "stringbuffer" equivalent in C#, in my : recent post. :) : : that : the
L*r
12 楼
hehe. In the old C/C++ tutorial, experts tell us to make a resonably long name. But actually, it doesn't hurt to write long meaningful name using vi, emacs or any IDE. Do you really write them character by character? No, typically you don't. Does it hurt to read a name like "stringbuffer"? No, I don't think so. So ... hehe. :) BTW, 'strbuf' and 'strbuilder'are ok as your own types. But there are many of beginners, the names of base classes have to be meaningful and damn easy to understand. :)
k
【在 w****n 的大作中提到】 : name is too long, hehe : why not 'strbuf' and 'strbuilder' hehe
w*n
13 楼
em... i'll write _s_b_ then do a full text replace :)
【在 L*******r 的大作中提到】 : hehe. In the old C/C++ tutorial, experts tell us to make a resonably long : name. : But actually, it doesn't hurt to write long meaningful name using vi, emacs or : any IDE. Do you really write them character by character? No, typically you : don't. : Does it hurt to read a name like "stringbuffer"? No, I don't think so. : So ... hehe. :) : BTW, 'strbuf' and 'strbuilder'are ok as your own types. But there are many of : beginners, the names of base classes have to be meaningful and damn easy to : understand. :)