C # Replaces all Chinese, punctuation, full-width turning half-width

Source: Internet
Author: User

       Private voidbtnStart_Click (Objectsender, EventArgs e) {            varSrcwords =Todbc (TxtSrc.Text.Trim ()); varPlacestr = Regex.Replace (Srcwords,@"([\p{p}*])"," "); Placestr= Regex.Replace (Placestr,@"([\u4e00-\u9fa5])",""); varSplitwords = Placestr.split (New string[] {" "}, Stringsplitoptions.removeemptyentries); varWords = Splitwords.tolist (). Select (item =            {                if(item. Length >0)                {                    varFirst = Item. Substring (0,1).                    ToUpper (); varLast =""; if(item. Length >2) { last= Item. Substring (1, item. length-1); }                    returnFirst +Last ; }                return "";            }); varJoinwords =string. Join (" ", words);            Clipboard.settext (joinwords); Txtdes.text=appendwords (joinwords); MessageBox.Show ("copied the replaced string to the Pasteboard"); }        /// <summary>        ///Replace all Chinese and punctuation marks./// </summary>        /// <param name= "str" ></param>        /// <returns></returns>        stringRemoveallchineseandsymbol (stringstr) {            varPLACESTR = Regex.Replace (str,@"([\p{p}*])"," "); Placestr= Regex.Replace (Placestr,@"([\u4e00-\u9fa5])",""); returnPlacestr; }        /// <summary>        ///Append and replace content/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>        stringAppendwords (stringstr) {            varAppend = Regex.Replace (Todbc (TxtAppend.Text.Trim ()),@"[\p{p}*]"," "); if(string. IsNullOrEmpty (Append)) {returnstr; }            varI=Combselect.selectedindex; if(i==0)            {                returnStr. Trim () +" "+append; }Else if(i==1)            {                returnAppend +" "+Str.            Trim (); }Else if(i==2)            {                varReplaceto=regex.replace (Todbc (TxtToReplace.Text.Trim ()),@"[\p{p}*]"," "); returnStr. Trim ().            Replace (Append, Replaceto); }            Else            {                returnstr; }        }        /// <summary>        ///full angle turning half angle/// </summary>        /// <param name= "input" ></param>        /// <returns></returns>         Public stringTODBC (stringinput) {            Char[] C =input.            ToCharArray ();  for(inti =0; i < c.length; i++)            {                if(C[i] = =12288) {C[i]= (Char) +; Continue; }                if(C[i] >65280&& C[i] <65375) C[i]= (Char) (C[i]-65248); }            return NewString (c); }        Private voidCombselect_selectedindexchanged (Objectsender, EventArgs e) {            varcb=(ComboBox) sender; Txttoreplace.visible= cb. selectedindex==2; }

C # Replaces all Chinese, punctuation, full-width turning half-width

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.