2017-11-01 8 views
0

私は、データベースフィールド内のテキストに置き換えられるテキスト文字列から電子メールアドレスを抽出する次のコードを持っています。Visual Basicプライバシーのために電子メールアドレスの特定の文字を置換してください

文字列には1つのメールアドレスが含まれます。 - 完全な電子メールアドレス

  • テスト - 電子メールユーザー
  • test.co.za - ドメイン
    1. [email protected]を次のように私はすでにメールアドレスを分割していますすべての文字を**************(フル電子メール)または個々の部分に置き換えることができるコードを含めました。

      私が必要なことをやったときに再びテキストを組み合わせるのは簡単です。

      私が取得しようとしています結果:

      テ** @ ********座

      は最初の2つの文字を除いて、最初の部分ですべてを隠れるくらいとして考えていました最後の部分、最後の2文字を除くすべて。

      Dim newText As string = "" 
      
      Dim senText As String = "This is a long string that we will try [email protected] 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) 
      

      ご協力いただければ幸いです。

    答えて

    4

    おそらく、代わりにこれを試してみてください。それが与える

    Dim email = "[email protected]" 
    
    Dim obsfucated = _ 
        String.Join("@", email.Split("@"c).Select(Function(x, n) _ 
         If(n = 0, _ 
          x.Substring(0, System.Math.Min(2, x.Length)).PadRight(x.Length, "*"c), _ 
          x.Substring(x.Length - 2, 2).PadLeft(x.Length, "*"c)))) 
    
    Console.WriteLine(obsfucated) 
    

    +0

    はそんなに@enigmativityありがとう、あなたは伝説の先生です! – Deedz

    0

    te**@********zaは、現在の電子メールのユーザーのサブでのネストされたサブストリングとパターンを設定します。サブストリングのネスト部分だけに****フィルタを適用します。正規表現

    でネストされたサブストリング詳細は

    Dim emailRegEx As New Regex("(\S{1,2}(\S*))@([^\.\s]+)(?:\.([^\.\s]+))+") 
    

    参照Here

    関連する問題