How can I read and parse the contents of this text file?

前端 未结 1 1461
滥情空心
滥情空心 2021-01-22 16:01

I want read a text file as C++ read it

here is example from the text file

(item(name 256) (desc 520)(Index 1)(Image \"Wea001\") (specialty  (aspeed 700))         


        
相关标签:
1条回答
  • 2021-01-22 16:32
    <?php
        $txt = '(item(name 256) (desc 520)(Index 1)(Image "Wea001") (specialty  (aspeed 700))(item   (name 257)  (desc 520)           (Index 2)  (Image "Wea002")(specialty(Attack 16 24)))';
    
        preg_match_all('/name\s+(?P<name>\w+).*desc\s+(?P<desc>\d+).*Index\s+(?P<index>\d+).*Image\s+(?P<img>.*)\).*specialty\s*\((?P<speciality>.*)\)\)\)/', $txt, $matches);
      foreach($matches['name'] AS $id => $name){
           echo 'name : '.$name.' <br> Desc : '.$matches['desc'][$id].'<br> Index : '.$matches['index'][$id].'<br> speciality : '.$matches['speciality'][$id].'';
    }
    

    Assuming you have always similar data format

    0 讨论(0)
提交回复
热议问题