当前位置:编程学习 > C#/ASP.NET >>

请教一个txt文件中数据的运算和再显示问题

zoo.txt文件内容如下 : 

¦--生物                                                                                           
                ¦--植物                                                                         
                                ¦--柳树                                          6       
                            ¦--向日葵                                        20       
                ¦--动物                                                                         
                                ¦--哺乳动物                                                 
                                                  ¦--猩猩                         5 
                                            ¦--大象                         8     
                                ¦--两栖动物                                             
                                                    ¦--青蛙                       30 
                                             ¦--鳄鱼                        7 
                ¦--微生物                                                                       
                                ¦--幽门杆菌                                        200       

要将其各子级值相加放到上一级后面,要求得出结果如下     zoo2.txt    

¦--生物                                                                                       276     
                ¦--植物                                                                      26 
                            ¦--柳树                                                         6       
                            ¦--向日葵                                                     20       
                ¦--动物                                                                     50 
                            ¦--哺乳动物                                                    13 
                                                ¦--猩猩                                  5 
                                                ¦--大象                                  8     
                            ¦--两栖动物                                                     37 
                                                ¦--青蛙                                  30 
                                                ¦--鳄鱼                                  7 
                ¦--微生物                                                                    200     
                             ¦--幽门杆菌                                                   200   

希望热心的朋友给出实现代码,谢谢!    --------------------编程问答-------------------- 可以试试用using reader对你说的txt文件进行读取,对每一行数据进行判断,如果符合条件则后面的数据进行计算,然后保存到新的文件中。 --------------------编程问答-------------------- ……看不懂…… --------------------编程问答--------------------


'//1.只给方法
'//2.读取所有zoo.txt的内容,定位各子级值,可以InStr(),相加,保存
'//3.建议你先多看点书......
'//4.建议用数据库,或以改变zoo.txt的保存格试.

补充:.NET技术 ,  VB.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,