How to replace string in qt
Hi All,
Need your help on urgent basis , as i am trying to replace the below string with respective value.Actually i am beginner on QT platform and i used replace function of qstring but it doesn't worked.Please find th below query on which i want to put specific value.
Query
select distinct(a.CALLING_NUMBER),b.cdr_details,a.CALLING _IMSI,a.CALLING_IMEI,a.CALLED_IMSI,a.CALLED_NUMBER ,a.CALLED_IMEI,a.CALLED_NUMBER_TON,a.LOC_AREA_CODE ,a.CELL_ID,a.MSC_ID,convert(varchar,start_time,105 ) +' '+ convert(varchar,start_time,108),a.DURATION,a.MSRN, LATITUDE,LONGITUDE,LOC_DETAIL from tbl_cdr_loader a,tbl_cdr_type_detail b,tbl_location_detail c where a.cdr_type=b.cdr_type and a.loc_area_code=c.loc_code and a.cell_id=c.cell_id and a.calling_number in ('<>','<>','<>','<>','<>')
Here I want to replace each angle brackets (<>) with specific value.I have these five input values "9831024841|9831024844|9831024843|9831024842|98310 24846" and it is seperated by |.
So atlast I want my output on below format.
select distinct(a.CALLING_NUMBER),b.cdr_details,a.CALLING _IMSI,a.CALLING_IMEI,a.CALLED_IMSI,a.CALLED_NUMBER ,a.CALLED_IMEI,a.CALLED_NUMBER_TON,a.LOC_AREA_CODE ,a.CELL_ID,a.MSC_ID,convert(varchar,start_time,105 ) +' '+ convert(varchar,start_time,108),a.DURATION,a.MSRN, LATITUDE,LONGITUDE,LOC_DETAIL from tbl_cdr_loader a,tbl_cdr_type_detail b,tbl_location_detail c where a.cdr_type=b.cdr_type and a.loc_area_code=c.loc_code and a.cell_id=c.cell_id and a.calling_number in ('9831024841','9831024844','9831024843','983102484 2','9831024842')
Request you all to please help me on urgent basis.
Thanks in advcance.
Regards,
Lekhraj Deshmukh
Re: How to replace string in qt
You will have to split the input values string, and iterate on your input query to replace each occurence of brackets.
I did not compile or test it, but here is the idea :
Code:
// input query
QString query
= "select distinct(a.CALLING_NUMBER),b.cdr_details,a.CALLING _IMSI,a.CALLING_IMEI,a.CALLED_IMSI,a.CALLED_NUMBER ,a.CALLED_IMEI,a.CALLED_NUMBER_TON,a.LOC_AREA_CODE ,a.CELL_ID,a.MSC_ID,convert(varchar,start_time,105 ) +' '+ convert(varchar,start_time,108),a.DURATION,a.MSRN, LATITUDE,LONGITUDE,LOC_DETAIL from tbl_cdr_loader a,tbl_cdr_type_detail b,tbl_location_detail c where a.cdr_type=b.cdr_type and a.loc_area_code=c.loc_code and a.cell_id=c.cell_id and a.calling_number in ('<>','<>','<>','<>','<>')" ;
// input numbers
QString inputNumbers
= "9831024841|9831024844|9831024843|9831024842|9831024846" ;
// split this string to retrieve actual numbers
// iterate on query and replace "on the fly"
foreach
(const QString & number, numbers
){
// find first occurence of brackets in query
int index = query.indexOf("<>") ;
if(index>=0)
{
// replace two characters ("<>") by the corresponding number
query.replace(index,2,number) ;
}
}
you will have to make sure input data is consistent, or add some check here and there to handle errors
Re: How to replace string in qt
Re: How to replace string in qt
Hi Totem,
Thanks for your reply.This solution helped me to solve my problem.
Thanks once again for your reply :)
Regards,
Lekhraj