本文介绍了电子邮件ID格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我的datablse表格列中有一个电子邮件地址作为用户名 我必须从数据库中选择它以便前两个字母和最后一个 两个字母仅在@ 之前可见,例如此电子邮件ID([email protected])应选择以下格式.. sa ............... [email protected],There is email address in my datablse table column as usernameI have to select it from database in such a way so that first two letter and lasttwo letters only visible before @for example this email id ([email protected]) should be selected in below [email protected]推荐答案SELECT SUBSTRING(userEmail, 1, 2) + REPLICATE('.', CHARINDEX('@', userEmail) - 5)+ SUBSTRING(userEmail, CHARINDEX('@', userEmail) - 2, 9999) AS [User Email] FROM MyTable 请注意,这不会进行任何错误检查...Do note that that doesn't do any error checking...DECLARE @emailAddress NVARCHAR(100) = '[email protected]'DECLARE @Prefix NVARCHAR(100)DECLARE @DomainName NVARCHAR(100)SET @Prefix = LEFT(@emailAddress, CHARINDEX('@', @emailAddress) - 1)SET @DomainName = RIGHT(@emailAddress, CHARINDEX('@', @emailAddress) - 2)--Assuming that prefix of email address is always 5 more chatactersDECLARE @PrefixStart NVARCHAR(100)DECLARE @PrefixEnd NVARCHAR(100)SELECT @PrefixStart = SUBSTRING (@Prefix, 1 , 2)SELECT @PrefixEnd = SUBSTRING (@Prefix, LEN(@Prefix) - 1 , LEN(@Prefix))SELECT @PrefixStart + REPLICATE('*', LEN(SUBSTRING (@Prefix, 3 , LEN(@Prefix) - 3))) + @PrefixEnd + '@' + @DomainNameusing System;public class Program{ public static void Main() { string email_id = "[email protected]"; int pos = email_id.IndexOf("@"); if (email_id.IndexOf("@") != -1) { string left_part = email_id.Substring(0, pos); Console.WriteLine(left_part); // sontosh_kumar_rch string first_two = left_part.Substring(0, 2); Console.WriteLine(first_two); // so string last_two = left_part.Substring(pos - 2); Console.WriteLine(last_two); // ch string right_part = email_id.Substring(pos); Console.WriteLine(right_part); // @yahoo.com string result = first_two + new String('.', pos - 4) + last_two + right_part; Console.WriteLine(result); // [email protected] } }} 这篇关于电子邮件ID格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 18:14