本帖最后由 star 于 2011-2-22 11:08 编辑 7 w1 o3 k x9 \, w- b- ^) p |9 c8 f k
这一久在给eb_exp debug,有个地方需要对字符串进行insert处理,原来的程序是这样写的:
" y4 k n- v$ w. v) m
result.insert(result.indexof(""), " (单位:分钟)");0 k/ k ^6 h ^ ] _* j* [* g
复制代码
调试过程中,发现返回的这个result的值没有改变,仍然是执行insert操作之前的值,于是去网上查,msdn()上有一条注意说明: ' j i% d$ ]7 o: ^6 h7 y4 w note & q# j' i$ o- u z
this method does not modify the value of the current instance. instead, it returns a new string in which value is inserted into the current instance." |$ b) f p& j
3 o" q' y8 e( s7 y
看了这句话就知道了,原来string的insert操作没有修改result的值,所以返回result的话,是不对的,应该返回insert方法的返回值,如下:
; |- k: n/ a9 o r
result = result.insert(result.indexof(""), " (单位:分钟)");5 b8 c, n8 k. s! i2 t d. ^