电子邮件ID格式 [英] Email ID formatting
本文介绍了电子邮件ID格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的datablse表格列中有一个电子邮件地址作为用户名
我必须从数据库中选择它以便前两个字母和最后一个
两个字母仅在@
之前可见,例如此电子邮件ID(sontosh_kumar_rch@yahoo.com)应选择以下格式..
sa ............... ch@yahoo.com
Hi,
There is email address in my datablse table column as username
I have to select it from database in such a way so that first two letter and last
two letters only visible before @
for example this email id (sontosh_kumar_rch@yahoo.com) should be selected in below format..
sa...............ch@yahoo.com
推荐答案
尝试:
Try:
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...
你可以这样开始:< br $>
在SQL中查看这些概念:
SUBSTRING [ ^ ]
REPLCATE [ ^ ]
CHARINDEX [ ^ ]
You can start something like this:
Look at these concepts in SQL:
SUBSTRING[^]
REPLCATE[^]
CHARINDEX[^]
DECLARE @emailAddress NVARCHAR(100) = 'HelloWorld@gmail.com'
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 chatacters
DECLARE @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 + '@' + @DomainName
在后面的代码处执行,而不是在sql中执行。 c#中的示例:
Do it at the code behind, not in sql. Example in c#:
using System;
public class Program
{
public static void Main()
{
string email_id = "sontosh_kumar_rch@yahoo.com";
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); // so.............ch@yahoo.com
}
}
}
这篇关于电子邮件ID格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文