从字符串中删除空格并转换为标题大小写

时间:2014-10-17 12:44:19

标签: sql

这是我想要输出的例子......

我有 输入 =“自动发送电子邮件

但我想要 输出 =“ AutomaticEmailSent

提前致谢!

3 个答案:

答案 0 :(得分:1)

使用TextInfo.ToTitleCase

// Defines the string with mixed casing. 
string myString = "Automatic email sent";

// Creates a TextInfo based on the "en-US" culture.
TextInfo myTI = new CultureInfo("en-US",false).TextInfo;

// Changes a string to titlecase, then replace the spaces with empty
string outputString = myTI.ToTitleCase(myString).Replace(" ", "");

答案 1 :(得分:1)

this answer窃取一个函数,该函数接受文本输入并使其成为正确的大小写(也称为标题大小写):

create function ProperCase(@Text as varchar(8000))
returns varchar(8000)
as
begin
   declare @Reset bit;
   declare @Ret varchar(8000);
   declare @i int;
   declare @c char(1);

   select @Reset = 1, @i=1, @Ret = '';

   while (@i <= len(@Text))
    select @c= substring(@Text,@i,1),
               @Ret = @Ret + case when @Reset=1 then UPPER(@c) else LOWER(@c) end,
               @Reset = case when @c like '[a-zA-Z]' then 0 else 1 end,
               @i = @i +1
   return @Ret
end

然后,您可以将此功能与REPLACE

结合使用
SELECT REPLACE(dbo.ProperCase(column), ' ', '')
FROM MyTable

答案 2 :(得分:0)

SQL Server

declare @value varchar(64) =  rtrim(' ' +  'Automatic email sent')
;with t(n) as (
    select n = charindex(' ', @value, 0)
    union all 
    select n = charindex(' ', @value, n + 1)
    from t
    where n > 0
)
select @value = stuff(@value, n + 1, 1, upper(substring(@value, n + 1, 1))) from t where n > 0
select replace(@value, ' ', '')