result.Insert(result.IndexOf("</p>"), " (单位:分钟)");4 y6 w7 R. A. ~6 {
复制代码
调试过程中,发现返回的这个result的值没有改变,仍然是执行Insert操作之前的值,于是去网上查,MSDN(http://msdn.microsoft.com/en-us/library/system.string.insert.aspx)上有一条注意说明: / T- @) B: t% s Note / j/ T2 T% R/ i7 X0 d7 T; }
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. ) @ ]6 W/ N4 t% p 2 f1 t' N, v9 s& J/ E看了这句话就知道了,原来string的Insert操作没有修改result的值,所以返回result的话,是不对的,应该返回Insert方法的返回值,如下:
# H5 n6 K# P. s% g, T: I5 @
result = result.Insert(result.IndexOf("</p>"), " (单位:分钟)"); - N, x( k3 S! K