PDA

View Full Version : chop String if more then 2 spaces are found



vitalic
20th April 2020, 13:20
Hi,

iI found out how to read something from stdout, Thx for the help.

Now i got my lines in a listview which works pretty well, but I Just need the first chracaters found in each line, as long as there is not more than 1 space.

Output in app:

13410

Output in terminal:



ubuntu@Laptop:~$ /opt/bin/mediaclient --scandabservices /dev/dab0
Service Name, Service ID, Component ID
EPG Deutschland 0xe0d110bc 0xc024
TPEG 0xe0d010bc 0xc023
TPEG_MM 0xe0d310bc 0xc021
Dlf 0xd210 0xa
Dlf Kultur 0xd220 0xb
Dlf Nova 0xd230 0xc
DRadio DokDeb 0xd240 0xd
Schwarzwaldradio 0x100d 0x7
ENERGY 0x1a45 0x4
SCHLAGERPARADIES 0x10c3 0x14
Absolut relax 0x17fa 0x3
RADIO BOB! 0x15dd 0x16
KLASSIK RADIO 0xd75b 0x6
sunshine live 0x15dc 0x15
Radio Horeb 0xd01c 0x5
ERF Plus 0x1a64 0x2
DRadio Daten 0xe0d00250 0xc001



As you can see there is some kind of difference but it would be enough in the first step, to have only the service name displayed in the listview.

The second step is to only read the first 6 characters of the service id, as this is needed for the next step, to tune to this service id.

Lesiok
20th April 2020, 14:11
Every time second column starts with 0x. So
QString service_name = line.left(line.indexOf(QLatin1String("0x")));
P.S.
Check if the separator is not tab.
P.S.2.

QStringList one_line = line.split('\t');
And you have a line divided into three elements.