字母大小写转换可以不用循环吗


字母大小写转换可以不用循环吗
2011年03月22日
  2011-03-22 wcdj 问题描述:
  i wanna to make a prog which convert small case letters entered by user to upper case letters....i TRIED to use toupper function ...but it only do action with a single character...is there any function which convert all characters like "lovely hakeem" to "LOVELY HAKEEM"
  (NOT BY LOOP)
  There is no way to convert all characters to upper or lower case without looping through the string. 
  下面总结几种常用的大写转小写的方法
  方法1:逐个字符判断,是大写字母+32
  #include  #include  int main() { char str[128]; gets(str); for (int i = 0; i = 'A' && str[i]  #include #include using namespace std; int main() { string str; cin>>str; transform(str.begin(),str.end(),str.begin(),tolowe r); cout #include  #include  char msg[] = "Some of THESE letters are Capitals\r\n"; char *p; void main( void ) { _cputs( msg ); /* Reverse case of message. */ for( p = msg; p  #include  int main( void ) { char string[100] = "The String to End All Strings!"; printf( "Mixed: %s\n", string ); _strlwr(string);// C库函数变小写 printf( "Lower: %s\n", string); _strupr(string);// C库函数变大写 printf( "Upper: %s\n", string); }  PS: A foreigner's method // You can do your own easily enough: // C #include  char* stoupper( char* s ) { char* p = s; while (*p = toupper( *p )) p++; return s; } // C++ #include  #include  #include  std::string& stoupper( const std::string& s ) { std::string result( s ); std::transform( s.begin(), s.end(), result.begin(), std::ptr_fun  ( std::toupper ) ); return result; } //Etc. Hope this helps.  更多内容参考:
  http://www.cplusplus.com/forum/general/33439/
  http://www.cplusplus.com/forum/beginner/14081/
  http://topic.csdn.net/u/20071015/21/4c266542-c3a6- 4a5a-9754-fc7574ca5ef6.html

猜你喜欢

转载自gqh36gqh.iteye.com/blog/1364678