zoukankan      html  css  js  c++  java
  • 大写字母或小写字母转换为数字

    大写字母或小写字母转换为数字A-->1,a-->1;B-->2,b-->2;C-->3,c-->3;...Z-->26,z-->26
     如果非字母转换为-1


    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    -- =============================================
    -- Author:      Insus.NET
    -- Blog:        https://insus.cnblogs.com
    -- Create date: 2019-05-23
    -- Update date: 2019-05-23
    -- Description: 大写字母或小写字母转换为数字A-->1,a-->1;B-->2,b-->2;C-->3,c-->3;...Z-->26,z-->26
    --                如果非字母转换为-1
    -- =============================================
    CREATE FUNCTION [dbo].[svf_ConvertLetterToNumber] 
    (
      @letter CHAR(1)
    ) RETURNS INT
    AS
    BEGIN
        DECLARE @ascii INT = -1
        IF LEN(ISNULL(@letter,'')) > 0 
        BEGIN        
            IF ASCII(@letter) % 65 + 1 <= 26
                SET @ascii = ASCII(@letter) % 65+ 1
    
            IF ASCII(@letter) % 97 + 1 <=26
                SET @ascii = ASCII(@letter) % 97 + 1
        END        
        
        RETURN @ascii
    END
    GO
    Source Code

    演示:

    SELECT 
    [dbo].[svf_ConvertLetterToNumber]('A') AS [A],
    [dbo].[svf_ConvertLetterToNumber]('a') AS [a],
    [dbo].[svf_ConvertLetterToNumber]('B') AS [B],
    [dbo].[svf_ConvertLetterToNumber]('b') AS [b],
    [dbo].[svf_ConvertLetterToNumber]('C') AS [C],
    [dbo].[svf_ConvertLetterToNumber]('c') AS [c],
    [dbo].[svf_ConvertLetterToNumber]('Z') AS [Z],
    [dbo].[svf_ConvertLetterToNumber]('z') AS [z],
    [dbo].[svf_ConvertLetterToNumber]('@') AS [@],
    [dbo].[svf_ConvertLetterToNumber]('$') AS [$]
    GO
    Source Code
  • 相关阅读:
    极大/小搜索,alpha/beta剪枝
    消息系统
    渲染主线程都在干什么
    好玩的虚拟CPU执行代码
    好玩的隐藏属性
    好玩的对象存储
    透视投影矩阵
    绕任意轴旋转
    视图变换
    正交投影矩阵
  • 原文地址:https://www.cnblogs.com/insus/p/10954054.html
Copyright © 2011-2022 走看看