簡體   English   中英

如何在asp.net中替換字符串中的特殊字符

[英]how to replace special character from string in asp.net

我的代碼 -

txtPhoneWork.Text.Replace("-","");
        txtPhoneWork.Text.Replace("_", "");
        txtMobile.Text.Replace("-", "");
        txtMobile.Text.Replace("_", "");
        txtPhoneOther.Text.Replace("-", "");
        txtPhoneOther.Text.Replace("_", "");

        location.ContactWork = txtPhoneWork.Text.Trim();
        location.ContactMobile = txtMobile.Text.Trim();
        location.ContactOther = txtPhoneOther.Text.Trim();

但它沒有替換,是否有任何方法,以便-_可以在單個函數中替換。

.Replace() 返回執行替換的字符串(它不會更改原始字符串,它們是不可變的),因此您需要這樣的格式:

txtPhoneWork.Text = txtPhoneWork.Text.Replace("-","");

在某個變量中獲取替換的字符串

你可以嘗試這個來替換單個函數字符串中的多個字符值= System.Text.RegularExpressions.Regex.replace(value,@“[ - _]”,“”);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM