C + + replaces the username part with a *

Source: Internet
Author: User

Summary: Very often the winning user does not want to let others know his ID. In the program we will set their account part to the * number display.

For example: Wangxiao, King * Two .

asadjsahd->a*********d.

Code:

#include <string.h> #include <stdlib.h> #define Tostar (str,start,end) do{for (int i=start;i<end;i++) { Str[i] = ' * ';} }while (0)//gbkconst char* tostarstring (const char* username) {int len = strlen (username); char *starname = new char[len+1];       strcpy (starname,username); int start = 1;                 Default reserved kinsoku character int end = len-1;unsigned char ch = starname[0]; Take the first character//if (Isalnum (ch)) {Tostar (starname,3,len-3);} if (ch >= 0xb0 && ch <= 0xf7)//infer if the header is Kanji {//Continue checking whether the next character can be organized into Chinese characters unsigned char ch1=starname[1];if ( CH1 >=0xa1 && ch1 <= 0xFE) {start = 2;}}           ch = starname[len-1]; Trailing character if (ch >=0xa1 && ch <= 0xFE) {unsigned char ch1=starname[len-2];if (ch1 >= 0xb0 && ch1 <= 0XF7) {end = Len-2;}} if (start<=end-1) Tostar (starname,start,end); else Tostar (Starname,end,len); return starname;} Unicodeconst wchar_t* tostarun (const wchar_t* username) {int len = wcslen (username); wchar_t *starname = new wchar_t[len+ 1];wcscpy(Starname,username), if (len>2) Tostar (starname,1,len-1), else if (len = = 2) Tostar (Starname,1,len); return starname;} 




C + + replaces the username part with a *

Related Article

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.