.net equivalent for php preg_replace

Posted by Hath on Stack Overflow See other posts from Stack Overflow or by Hath
Published on 2010-03-12T14:27:49Z Indexed on 2010/03/12 14:37 UTC
Read the original article Hit count: 164

Filed under:
|
|

What is the c#.net equivalent for php's preg_replace function?

php code is like this:

    const ALLOW_VALUES = '[^a-z0-9àáâäèéêëìíîïòóôöùûwýÿyÁÂÄÈÉÊËÌÎÏÒÓÔÖÙÛÜWYÝ]';

    public function streetTownHash($data, $hashCheck = false, $updateRecord = false)
     {
       foreach($data as $key=>$value){
        try{
         $value = mb_convert_case($value, MB_CASE_LOWER, "UTF-8");
         } catch(Exception $e) {
          echo "Requires extension=php_mbstring.dll enabled !  - $e";
         }
        $valueConcat .= preg_replace('/'.self::ALLOW_VALUES.'/','',$value); # Remove punctuation etc
       }
       $streetTownHash =  sha1($valueConcat);

....

this is as far as i've got but not sure about it..

private SHA1 hash = SHA1.Create();
private string hashAllowed = "[^a-z0-9àáâäèéêëìíîïòóôöùûwýÿyÁÂÄÈÉÊËÌÎÏÒÓÔÖÙÛÜWYÝ]";

public string HashString(string value)
{
    value = // = regex not sure this part

    var bytes = ASCIIEncoding.UTF8.GetBytes(value);
    var hashed = hash.ComputeHash(bytes);
    return ASCIIEncoding.UTF8.GetString(hashed);
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about php