【发布时间】:2018-04-13 14:52:43
【问题描述】:
我有以下代码将从文本字符串中提取电子邮件地址,该地址将被数据库字段中的文本替换。
字符串将包含一个电子邮件地址。我已经将邮箱地址拆分如下:
- test@test.co.za - 完整的电子邮件地址
- 测试 - 电子邮件用户
- test.co.za - 域
我已包含可以将所有字符替换为 ***************(完整电子邮件)或单个部分的代码。
当我完成我需要的工作后,再次组合文本会很容易。
我想要得到的结果:
te**@********za
正在考虑隐藏第一部分中的所有内容,除了前 2 个字符,在最后一部分中,除了最后 2 个字符之外的所有内容。
Dim newText As string = ""
Dim senText As String = "This is a long string that we will try test@test.co.za to extract the email address from, it might exist anywhere in this string."
Dim emailRegEx As New Regex("(\S+)@([^\.\s]+)(?:\.([^\.\s]+))+")
Dim m As Match = emailRegEx.Match(senText)
If m.Success Then
newText = m.ToString
End If
Dim mystr As String = newText
Dim cut_at As String = "@"
Dim x As Integer = InStr(mystr, cut_at)
Dim string_before As String = mystr.Substring(0, x - 1)
Dim string_after As String = mystr.Substring(x + cut_at.Length - 1)
Dim myString As String = New String("*"c, newText.Length)
Dim PrivateMail As String = ""
response.write(newText)
response.write(myString)
response.write(string_before)
response.write(string_after)
任何帮助将不胜感激。
【问题讨论】: