欧美free性护士vide0shd,老熟女,一区二区三区,久久久久夜夜夜精品国产,久久久久久综合网天天,欧美成人护士h版

首頁綜合 正文
目錄

柚子快報(bào)邀請(qǐng)碼778899分享:替換正則表達(dá)式c#

柚子快報(bào)邀請(qǐng)碼778899分享:替換正則表達(dá)式c#

http://yzkb.51969.com/

1、替換最后一個(gè)字符

??? dto.ContactPerson = dto.ContactPerson.ReplaceName("*");

??? ///

??? /// 替換最后一個(gè)字符串 ??? /// ??? /// ??? /// ??? /// ??? public static string ReplaceName(this string oldStr, string newStr) ??? { ??????? string pattern = @"(.)$"; ??????? string result = Regex.Replace(oldStr, pattern, newStr);

??????? return result; ??? }

2、替換除第一字符外其他都替換成*

??????? 注意:new string('*', m.Groups[2].Length) 是表示根據(jù)第一個(gè)字符后又幾個(gè)字符來生成相應(yīng)得*號(hào)來替換

?dto.ContactPerson = dto.ContactPerson.ReplaceName();

??? ///

??? /// 替換第一個(gè)字符后得其他字符串 ??? /// ??? /// ??? /// ??? /// ??? public static string ReplaceStr(this string oldStr) ??? { ??????? // 正則表達(dá)式:匹配第一個(gè)字符之后的所有字符 ??????? string pattern = "(.)(.*)"; ??????? string result = Regex.Replace(oldStr, pattern, m => m.Groups[1].Value + new string('*', m.Groups[2].Length));

??????? return result; ??? }

或則自定義替換成你想要得字符

dto.ContactPerson = dto.ContactPerson.ReplaceStr('-');

??? ///

??? /// 替換第一個(gè)字符后得其他字符串 ??? /// ??? /// ??? /// ??? /// ??? public static string ReplaceStr(this string oldStr, char newStr) ??? { ??????? // 正則表達(dá)式:匹配第一個(gè)字符之后的所有字符 ??????? string pattern = "(.)(.*)"; ??????? string result = Regex.Replace(oldStr, pattern, m => m.Groups[1].Value + new string(newStr, m.Groups[2].Length));

??????? return result; ??? }

?

3、隱藏手機(jī)號(hào)

???????? dto.ContactNumber = PhoneExtensions.GetPhoneHidden(demand.ContactNumber);

???????? ///

??????? /// 獲取隱藏中間四位的手機(jī)號(hào)碼 ??????? /// ??????? /// ??????? /// ??????? public static string GetPhoneHidden(this string phone, bool isValidateTelePhone = true) ??????? { ??????????? //如果固化則不隱藏 ??????????? if (isValidateTelePhone && IsTelePhoneNumber(phone)) ??????????? { ??????????????? return phone; ??????????? } ??????????? return Regex.Replace(phone, "(\\d{3})\\d{4}(\\d{4})", "$1****$2"); ??????? }

??????? ///

? ??????? /// 驗(yàn)證固定電話號(hào)碼 ? ??????? /// [3位或4位區(qū)號(hào);區(qū)號(hào)可以用小括號(hào)括起來;區(qū)號(hào)可以省略;區(qū)號(hào)與本地號(hào)間可以用減號(hào)或空格隔開;可以有3位數(shù)的分機(jī)號(hào),分機(jī)號(hào)前要加減號(hào)] ? ??????? /// ? ??????? /// 待驗(yàn)證的字符串 ? ??????? /// 是否匹配 ? ??????? public static bool IsTelePhoneNumber(string input) ??????? { ??????????? string pattern = @"^(((0\d2|0\d{2})[- ]?)?\d{8}|((0\d3|0\d{3})[- ]?)?\d{7})(-\d{3})?$"; ??????????? return IsMatch(input, pattern); ??????? }

柚子快報(bào)邀請(qǐng)碼778899分享:替換正則表達(dá)式c#

http://yzkb.51969.com/

推薦文章

評(píng)論可見,查看隱藏內(nèi)容

本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場。

轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。

本文鏈接:http://m.gantiao.com.cn/post/19050956.html

發(fā)布評(píng)論

您暫未設(shè)置收款碼

請(qǐng)?jiān)谥黝}配置——文章設(shè)置里上傳

掃描二維碼手機(jī)訪問

文章目錄