Results 1 to 4 of 4

Thread: How to replace string in qt

  1. #1
    Join Date
    Sep 2011
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  2. #2
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default 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 :

    Qt Code:
    1. // input query
    2. 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 ('<>','<>','<>','<>','<>')" ;
    3. // input numbers
    4. QString inputNumbers = "9831024841|9831024844|9831024843|9831024842|9831024846" ;
    5. // split this string to retrieve actual numbers
    6. QStringList numbers = inputNumbers.split("|", QString::SkipEmptyParts) ;
    7.  
    8. // iterate on query and replace "on the fly"
    9. foreach(const QString & number, numbers)
    10. {
    11. // find first occurence of brackets in query
    12. int index = query.indexOf("<>") ;
    13. if(index>=0)
    14. {
    15. // replace two characters ("<>") by the corresponding number
    16. query.replace(index,2,number) ;
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    you will have to make sure input data is consistent, or add some check here and there to handle errors

  3. The following user says thank you to totem for this useful post:

    lekhrajdeshmukh (24th October 2011)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to replace string in qt

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    Join Date
    Sep 2011
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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

Similar Threads

  1. [java] string.replace
    By mickey in forum General Programming
    Replies: 3
    Last Post: 7th September 2010, 07:04
  2. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  3. replace string in QList<QStringList>
    By estanisgeyer in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2008, 17:40
  4. How do I replace a widget?
    By pir in forum Qt Programming
    Replies: 4
    Last Post: 24th July 2006, 16:51

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.