Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

onvert it to lower case letter if it’s an upper case letter and convert it to upper case letter if it’s a lower

#include<iostream>
#include<string>
using namespace std; 

int main() 
{ 
    string str="Hello World"; 
    int i;
    
    cout<<"The String is: 
"<<str;
    cout<<endl<<endl;
    
    cout<<"String after uppercase lowercase modification: 
";
    for(i=0; i < str.length(); i++)
    {
        //if its uppercase add to its Ascii code 32 to make lowercase
        if(str[i]>='A' && str[i]<='Z')
      	cout<<char(str[i]+32);
      	
      	// else if its lowercase subtract 32 to make it upper case 
        else if(str[i]>='a' && str[i]<='z')
      	cout<<char(str[i]-32);
      	
      	// else if its a space or symbol for example just print it as is
      	else cout<<str[i];
      	
      	//the reason this works is that the distance in Ascii from uppercase to lowercase 
      	//is standard and constant
    }
    return 0;
}
Source by www.knowprogram.com #
 
PREVIOUS NEXT
Tagged: #onvert #case #letter #upper #case #letter #convert #upper #case #letter
ADD COMMENT
Topic
Name
9+6 =