In fact, I want to write this article for a long time, just all kinds of conditions, so I can't think of what I have learned is good for everyone. I hope that this technology can be useful to everyone. When I did a large system, I used to develop a set of controls, one of which is the control of the supplier name, that is, operators do not have to be from a lot of suppliers. Select or enter the code or write the whole people written to the vendor name, a bit like the Search of the Shan Mountain. Later, some colleagues have developed other systems. They use operators to enter the first alphabet of Chinese characters, I feel very good, but later, I know that the pinyin of these inputs will add a list to store this pinyin, this The situation gives me a lot of inspiration, how can I convert an arbitrary Chinese character to the first letter of the Chinese characters? I downloaded a Delphi program code on the Internet. There are most of the Chinese characters corresponding to the Pinyin. I have processed the data into the database and do some processing, and then I have written a database function to convert. The function is implemented, I put this function code up, but the data of the Pinyin control table of the database has tens of thousands of data, so I will designate an address to let friends who are interested in download. As for the efficiency problem, I have been testing: 256M memory, 2.0g class Yang, convert 80,000 Chinese characters take the time for about 3 seconds, of course, this function is mainly applied to a table of hundreds of data, mainly for the operator Convenient .create function dbo.spellcode (@sttext as varchar (1000)) Returns varchar (1000) asbegin declare @returnValue as varchar (1000), @lowValue as int, @apy as varchar (10)
Set @ ReturnValue = '' While (@sttext)> 0) Begin if (@ sttext, 1)> = 'a' AND left (@ sttext, 1) <= 'z') or (@ @ @ @ @@ StTEXT, 1)> = 'A' AND left (@ sttext, 1) <= 'z') or (@ sttext, 1)> = '0' AND left (@ sttext, 1) <= '9' Begin set @ returnvalue = @ RETURNVALUE UPPER (LEFT (@ sttext, 1)) set @ sttext = right (@ sttext, len (@sttext) -1) Continue End
Set @ lowValue = ASCII (@ sttext, 1)) if @lowvalue <= 128 - Control characters and special characters do not process begin --set @ returnvalue = @ ReturnValue Upper (left (@ stTTEXT, 1)) If you need to display set @ sttext = right (@ sttext, len (@sttext) -1) Continue End set @ highvalue = cast (cast (@ sttext, 1) as varbinary AS INT) - @ lowValue * 256 if @ lowvalue = 166 - Greek letter Begin set @ Apy = Case when @highvalue> = 161 and @highvalue <= 184 THEN (SELECT LEFT (InfoValue, 1) from chineseespells where rowid = @ highvalue-160 and typeinfo = 3) WHEN @highvalue> = 193 and @highvalue <= 216 then (select left (infovalue, 1) from ChineseSpellS where rowid = @ highvalue-192 and typeinfo = 3) end set @ ReturnValue = @ ReturnValue Upper (@Apy) set @stText = Right (@sttext, LEN (@sttext) -1) Continue End - Get Pinyin Index Select @ Apy = Left (InfoValue, 1) from ChinesePell with (NOLOCK) Where RowId = @ @ @ highvalue-63 if @apy is null Set @ Apy = dbo.chtoen (@ sttext, 1)) set @ReturnValue = @ReturnValue Upper (@APY) set @ sttext = right (@ sttext, len (@sttext) -1) End
Return @returnValuend