Results 1 to 5 of 5

Thread: Reading text file line part by part

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2014
    Posts
    71
    Thanks
    13
    Qt products
    Qt5
    Platforms
    Windows

    Question Re: Reading text file line part by part

    According to my new Requirement I have to spilt the below line as
    For example
    FUNC(Std_ReturnType, RTE_CODE) Rte_Read_PA_BSW_comEBCM_CAN1_PDU82_IElecPrkBrkAppl Stat(CONSTP2VAR(IElecPrkBrkApplStat, AUTOMATIC, RTE_APPL_DATA) data)

    My result Should as below
    1.FUNC
    2.Std_ReturnType, RTE_CODE
    3.Rte_Read_PA_BSW_comEBCM_CAN1_PDU82_IElecPrkBrkAp plStat
    4.CONSTP2VAR(IElecPrkBrkApplStat, AUTOMATIC, RTE_APPL_DATA) data
    I tried many way to spilt but not got the exact Result
    Example
    Qt Code:
    1. list = line.split(QRegularExpression("\\W+"), QString::SkipEmptyParts);
    2.  
    3. list = line.split("(");
    4.  
    5. list = line.split(")");
    6.  
    7. list = line.split("()");
    8.  
    9. list = line.split(" ");
    To copy to clipboard, switch view to plain text mode 
    but all does not provide me the exact Result Please let me know if any idea.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Reading text file line part by part

    QString::split() alone might not be enough or not applicable at all.

    If the pattern of the whole line is describable as a regular expression you could use QRegularExpression to match and capture the parts.
    If the pattern is not describable as a regular expression, you can check for the tokens manually and then use sub string functions such as mid() to extract the parts.

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 23rd August 2011, 12:23
  2. Replies: 3
    Last Post: 8th June 2011, 06:36
  3. Replies: 2
    Last Post: 21st May 2010, 14:32
  4. Replies: 1
    Last Post: 6th November 2009, 10:03
  5. How to make some part of text underlined in QLineEdit?
    By blonde in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2009, 09:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.