C ++ character (char) and string (string) Operations

Source: Internet
Author: User

1. Determine whether a string contains non-numeric characters

# Include <string>

 

Bool ischar (string judstr)
{
Char szbuf [2];
While (judstr. Length ()! = 0)
{
Strcpy_s (szbuf, (judstr. substr (0, 1). c_str ());

Int c = (INT) (szbuf [0]);

Judstr = judstr. substr (1, sizeof (judstr) + 1 );

// If any of the string is character, then this string is a character, return true.
If (isalpha (c ))
{
Return true;
}
}
// If all of the string is number, the string is number, return true.
Return false;
}

 

2. Convert all characters in a string to uppercase.

# Include <string>

String uperstring (string Str)
{
Char szbuf [2];
String restr = "";
String temp_word = "";

While (Str. Length ()! = 0)
{

Strcpy_s (szbuf, (Str. substr (0, 1). c_str ());

Int c = (INT) (szbuf [0]);

Temp_word = toupper (C );

STR = Str. substr (1, sizeof (STR) + 1 );

Restr = restr + temp_word;

}

// If all of the string is number, the string is number, return true.
Return restr;
}

3. Convert string to Char

Char szbuf [2];
Strcpy_s (szbuf, (pointer-> word). substr (0, 1). c_str ());

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.