locked
Method String.Normalize doesn't work. RRS feed

  • Question

  • Hi,

    I'm trying to use String.Normalize method and doesn't work.

    using System.Text;
    using System;
    
    namespace App.Common
    {
        static class StringExtensions
        {
            public static string RemoveAccents(this string s)
            {
                string ra = s.Normalize(); //<-- red line
                
            }
        }
    }

    I've see:

    'string' does not contain a definition for 'Normalize' and no extension method 'Normalize' accepting a first argument of type 'string' could be found

    Sunday, January 12, 2014 2:59 PM

Answers

  •   

    Is this for a Windows 8 Store App that will run on a WinRT? If so I do believe that in WinRT it is not supported. I found some code that should remove accent marks on characters you may try something like this.

    string accentedStr;
    byte[] tempBytes;
    tempBytes = System.Text.Encoding.GetEncoding("ISO-8859-8").GetBytes(accentedStr);
    string asciiStr = System.Text.Encoding.UTF8.GetString(tempBytes);
    I found this on stackoverflow in one of the comments.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Fabio Guaraldo Tuesday, January 14, 2014 12:47 AM
    Monday, January 13, 2014 7:39 PM

All replies

  • Hi Fabio;

    The only thing I see lacking in the extension method is to return ra as shown below.

    public static string RemoveAccents(this string s)
    {
        string ra = s.Normalize();
        return ra;            
    }


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Proposed as answer by HomeGrownCoder Sunday, January 12, 2014 4:39 PM
    Sunday, January 12, 2014 3:53 PM
  • Are you using a very old version of .Net?  Normalize() was introduced in .Net V2.0

    Paul Linton

    Sunday, January 12, 2014 10:55 PM
  • The only thing I can think of is you are using a very old version of .NET framework.

    As Paul mentioned String.Normalize Method was introduced with .NET Framework 2.0. If your target framework is .NET 2.0 or above, your code should work.


    Happy Coding.

    Regards,
    Jaliya Udagedara (MCPD,MCSD) | My Blog

    Monday, January 13, 2014 5:34 AM
  • I'm developing for windows 8 apps.

    I think that I'm using the lastest version of the .NET Framework.

    Monday, January 13, 2014 7:06 PM
  •   

    Is this for a Windows 8 Store App that will run on a WinRT? If so I do believe that in WinRT it is not supported. I found some code that should remove accent marks on characters you may try something like this.

    string accentedStr;
    byte[] tempBytes;
    tempBytes = System.Text.Encoding.GetEncoding("ISO-8859-8").GetBytes(accentedStr);
    string asciiStr = System.Text.Encoding.UTF8.GetString(tempBytes);
    I found this on stackoverflow in one of the comments.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Fabio Guaraldo Tuesday, January 14, 2014 12:47 AM
    Monday, January 13, 2014 7:39 PM