简体   繁体   中英

Convert Non-English text into English text using SQL

I have text normalizing method, I use it to convert non-English letters into English letters only.

I need to do the same functionality using SQL server


C# Method:

  private  string normalizeString(string inputWord)
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (char c in inputWord.Trim().ToCharArray())
            {
                string normalizedChar = c.ToString()
                    .Normalize(NormalizationForm.FormD).Substring(0, 1);

                stringBuilder.Append(normalizedChar);
            }

            return stringBuilder.ToString();
        }

Example

Ä => A
ä => a
Ö => O
ö => o
Õ => O
õ => o
Ü => U
ü => u

As per this Question there's no such native function in SQL Server. What you can do is to create a CLR Function for that.

if you want to remove diacritics you can use Collate

for example:

select 'áéíóú' collate SQL_Latin1_General_Cp1251_CS_AS

this will return "aeiou"

Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM