Home > OS >  Format string based on word match
Format string based on word match

Time:04-24

I ran out of ideas. I need to format this text creating a paragraph for each instance of the word 'Group'.

Notice Group1, Group2:

('uniqueName', 'Group', True ),
('Value', 'float', 0, 5, 1 ),
('Value', 'int', 1 ),
('Value', 'bool', true),
('uniqueName', 'Group', True ),
('Value', 'bool', true),
....

I need to separate this is in two paragraphs:

('uniqueName', 'Group', True ),
('Value', 'float', 0, 5, 1 ),
('Value', 'int', 1 ),
('Value', 'bool', true),

('uniqueName', 'Group', True ),
('Value', 'bool', true),

Each group represents the parameters below it, so Group1 have value1 - value3. The groups and values share the same pattern so is being difficult. I'm using QT with QString.

CodePudding user response:

Thanks to Aconcagua's comment I found a solution. Just had to check for each Group match and add a new line before copying the line to the file. Then check for everything that was not a group and add it to the file after adding the group:

If(Group)
{ // add a blank line
  // Copy the group to the file
}

if(!Group)
{
  // Copy the line to the file
}
  •  Tags:  
  • c qt
  • Related