Str is probably a String variable declared. Usually when we declare String objects we prefix it with the character str. example: String strName = "";
As of Java 1.6 it has 3: StringTokenizer(String str) StringTokenizer(String str, String delim) StringTokenizer(String str, String delim, boolean returnDelims)
Use for loop declare string array str[] and string variable l= string length of string array j=l for i=0 to i=l/2 then temp=str[i] str[i]=str[j-1] str[j-1]=temp j=j-1 now print str array it will be reversed
Here's a simple C program to display vowels from a given string: #include <stdio.h> int main() { char str[100]; printf("Enter a string: "); fgets(str, sizeof(str), stdin); printf("Vowels in the string: "); for (int i = 0; str[i] != '\0'; i++) { if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U') { printf("%c ", str[i]); } } return 0; } This program prompts the user for a string, then iterates over each character to check if it's a vowel, and displays the vowels found.
Str converts a number to a string.
main(){ char str[5]="hello"; if(str==NULL) printf("string null"); else printf("string not null"); }
#include<stdio.h> int main() { char str[100]; int i; printf("Please enter a string: "); // gets(str); // fgets is a better option over gets to read multiword string . fgets(str, 100, stdin); // Following can be added for extra precaution for '\n' character // if(str[length(str)-1] == '\n') str[strlen(str)-1]=NULL; for(i=0;str[i]!=NULL;i++) { if(str[i]>='A'&&str[i]<='Z') str[i]+=32; else if(str[i]>='a'&&str[i]<='z') str[i]-=32; } printf("String in toggle case is: %s",str); return 0; }
#include <string> #include <iostream> using namespace::std; ... string str = "This is a test"; cout << str << endl; str = "This is also a test"; cout << str << endl; Gives you ... This is a test This is also a test
Here is a simple C program to check if a string is a palindrome: #include <stdio.h> #include <string.h> int main() { char str[100], rev[100]; printf("Enter a string: "); fgets(str, sizeof(str), stdin); str[strcspn(str, "\n")] = 0; // Remove newline character strcpy(rev, str); strrev(rev); // Reverse the string if (strcmp(str, rev) == 0) printf("The string is a palindrome.\n"); else printf("The string is not a palindrome.\n"); return 0; } This program takes a string input, reverses it, and then compares the original string with the reversed string to determine if it is a palindrome.
String itself is an object dude... If you want an object out of a string then you can do this. Object obj = (Object) str; //str is the String you want to convert to object.
#include<stdio.h> #include<conio.h> #include<string.h> int main() { int tmp,i; char str[30]; printf("Enter any string: "); gets(str); for(i=0; str[i]!='\0'; i++) { if(str[i-1]==' ' i==0) { if(str[i]>='a' && str[i]<='z') str[i]=str[i]-32; else if(str[i]>='A' && str[i]<='Z') str[i]=str[i]+32; } printf("%c",str[i]); } getch(); return 0;}
[ string toupper $str ] or [ string tolower $str ]
(strlen(str) == 0) ? '\0' : str[strlen(str)-1]