Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo an alle,

mein Problem ist, dass zwei Strings, die augenscheinlich gleich sind es doch nicht sind.

Ich habe einen String1, der aus einer XML-Datei mit Codierung utf-8 kommt:

Halldór Laxness. Aus dem Isländischen übertragen von Ernst Harthern

Ich habe einen String2, der auch aus einem XML-Stream kommt, der laut "Hersteller" auch utf-8-Codiert ist:

Halldór Laxness. Aus d. Isländ. übers. von Ernst Harthern (hier sind z. Bsp. auch die ä-Pünktchen neben dem Buchstaben)

Wenn ich beide Strings durch CW2A(CP_UTF8) schicke erhalte ich folgendes:

String1: Halldór Laxness. Aus dem Isländischen übertragen von Ernst Harthern

String2: HalldoÃŒÂr Laxness. Aus d. Isländ. übers. von Ernst Harthern

Beides ist wohl sachlich richtig. Wie bekomme ich aber den String2 in das Format von String1, damit ich die vergleichen kann bzw. finde ich in String2 nicht String2.Find(L"Isländ.").

Genutzt wird VC++ 2010, UNICODE, MFC.

  • Autor

So ist es. Das wollte ich auch gerade schreiben.

Angepasst aus der MSDN:


CString strText=L"Halldór Laxness. Aus d. Isländ. übers. von Ernst Harthern"


if(!IsNormalizedString(NormalizationC, strText, strText.GetLength()))

 {

  int iSizeGuess=0;

  LPWSTR pBuffer=NULL;


  // How big is our buffer (quick guess, usually enough) 

  iSizeGuess = NormalizeString(NormalizationC, strText, -1, NULL, 0);


  while(iSizeGuess > 0)

   {

    pBuffer = (LPWSTR)malloc(iSizeGuess * sizeof(WCHAR));


    if(pBuffer)

     {

      // Normalize the string 


      int iActualSize = NormalizeString(NormalizationC, strText, -1, pBuffer, iSizeGuess);

      iSizeGuess = 0;


      if (iActualSize <= 0 && GetLastError() != ERROR_SUCCESS)

       {

        // Error during normalization 

        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)

         {

          // If the buffer is too small, try again with a bigger buffer. 

          iSizeGuess = -iActualSize;

         }//end if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)


        else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION)

         {

         }//end else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION)

       }//end if (iActualSize <= 0 && GetLastError() != ERROR_SUCCESS)


      else

       {

        // Display the normalized string 

       }//end else by if (iActualSize <= 0 && GetLastError() != ERROR_SUCCESS)


      strText=pBuffer;

       // Free the buffer 

      free (pBuffer);

     }//end if(pBuffer)

    else

     {

      iSizeGuess = 0;

     }//end else by if(pBuffer)

   }//end while(iSizeGuess > 0)

 }//end if(!IsNormalizedString(NormalizationC, strKurzText, strKurzText.GetLength()))


return strText;

Man erhält dann einen String, den man auch vergleichen kann.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.