Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Comparing unicode chars
Forum Updated to NodeBB v4.3 + New Features

Comparing unicode chars

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sohoquetaros
    wrote on last edited by
    #1

    Hello together,

    maybe this is a very simple thing, but I didn't find any solution yet:

    I want to compare char by char a QString - like this

    @for (i = 0; i < message.length(); i++) {
    if (message[i] == 'ä')
    // do somthing
    @

    The point is: it doesn't work. "ä" is a 16bit unicode char and I don't know how to to the comparison right.

    Can anybody help me? That would be very nice.

    Best regards

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      Just use QChar with either 16-bit code in constructor or cell and row constructor instead of 'ä'.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sohoquetaros
        wrote on last edited by
        #3

        Many thanks, this solves my problem !

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          Are you aware that 'ä' can be encoded in different ways in unicode? Your simple comparison only detects one way to encode it!

          You might want to normalize (see "QString::normalized":http://doc.qt.nokia.com/4.7/qstring.html#normalized) both strings before comparing them or be prepared to have strings that produce the same sequence of glyphs (the little drawings on the screen) be considered different.

          Some normalization forms encode 'ä' in a sequence of unicode codepoints. In that case your character-by-character comparison will miss it.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved