今天在写一个小函数时遇到个囧事,被string.Replace给拦住了。
string.Replace是要求有返回值的,由于昨天刚刚结束一个asp程序,就习惯的写成了string.Replace(old value,new value),结果浪费了我N久的时间找错误,郁闷。
Old Code:
1 2 3 4 5 6 7 8 9 | private string cutStringBlank(string strline) { strline=strline.Trim(); do { strline.Replace(' ',' '); }while(strline.IndexOf(' ')!=-1); return strline; } |
这是用来将一含有不定长度空格的字符串转换成间隔空格为1个字符的函数,以便于能够string.Split()
New Code:
1 2 3 4 5 6 7 8 9 | private string cutStringBlank(string strline) { strline=strline.Trim(); do { strline=strline.Replace(' ',' '); }while(strline.IndexOf(' ')!=-1); return strline; } |
特别要注意的是,Old Code在编译和运行时是没有错误的,所以我一直没有找到这个错误所在[:face_39:]
很好,就是這個問題,呵呵
I put a WordPress blog on my website a few days ago, and I was just curious about how it works. So I just want to know if all the posts are saved into a single file or if they are separate for each post. Then I also want to know where they can be found on my server. Thanks.