Results 1 to 6 of 6

Thread: QString comparision with some different char

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QString comparision with some different char

    Hi,

    I want to compare to QStrings and I want to know how many chars are different.
    I have a QString that I need to search on a QStringList, eg: search "ADLSHERPOA" on a QStringList with elements like "BAHDOMAYTC;GAPCLAUIBG;ADLSHERPOB" that can contain some errors

    Have I to use QRexExp or it's better to compare all the chars one by one? Think on that it must be a fast solution(speed is important).

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString comparision with some different char

    What is the outcome that you want? Please show some example inputs and outputs.

    It is not clear what you mean when you say some strings will contain errors.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QString comparision with some different char

    Hi,

    QStrinList containing "BAHDOMAYTC;GAPCLAUIBG;ADLSHERPOB"
    QString containing "ADLSHERPOA".

    I want to search the QString "ADLSHERPOA" on every QStringList trying to find the same element. If the element is different, I want to know how many chars are different. In this case, comparing "ADLSHERPOA" with "BAHDOMAYTC" will return 10 errors. Comparing "ADLSHERPOA" with "GAPCLAUIBG" will also return 10 errors. Comparing "ADLSHERPOA" with "ADLSHERPOB" will return 1 error.

    Thanks,
    Òscar Llarch i Galán

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

    Default Re: QString comparision with some different char

    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. The following user says thank you to wysota for this useful post:

    ^NyAw^ (18th May 2013)

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QString comparision with some different char

    The options depend a little on the precise nature of your strings and what you mean by the number of differences. Are the strings are always 10 characters long, not actual words, and a difference is counted if corresponding characters are different? Since you want to know the error count in all cases I don't see a generally fast method of doing this. You need to compare every character of every string with corresponding character in the candidate string.

    In general terms you are looking for something like Levenshtein distance or a similar measure.

    If you are doing this to provide some sort of speling correcshun then you might find this article interesting. http://www.norvig.com/spell-correct.html

  7. The following user says thank you to ChrisW67 for this useful post:

    ^NyAw^ (18th May 2013)

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

    Default Re: QString comparision with some different char

    Quote Originally Posted by ChrisW67 View Post
    Since you want to know the error count in all cases I don't see a generally fast method of doing this.
    It depends whether the comparison is done once or multiple times against the same set of strings. If the latter then a smart structure based on a radix trie (or some other kind of trie) might be able to speed things up.
    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.


Similar Threads

  1. QString to char*
    By giginjose in forum Newbie
    Replies: 5
    Last Post: 11th June 2010, 10:19
  2. QString to char*
    By peace_comp in forum Qt Programming
    Replies: 4
    Last Post: 27th May 2008, 07:08
  3. QString to Char
    By kenny_isles in forum Newbie
    Replies: 1
    Last Post: 23rd February 2007, 09:51
  4. char* from QString
    By bruccutler in forum Newbie
    Replies: 16
    Last Post: 14th February 2007, 06:36
  5. QString to char
    By boss_bhat in forum Qt Programming
    Replies: 7
    Last Post: 20th July 2006, 23:26

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.