C# :: Capitalize First Letter In Every Word In A String?
Jan 7, 2014
I have a difficulty with string methods for some reason. I tried solving a question from my book, which requires me to capitalize the first letter of every word in a string. I kept trying for maybe two hours yesterday, re-reading the string chapter to see if I'm forgetting a certain method or if something similar was discussed in the examples but I didn't find anything. I also googled it, and found a few answers, none of which I understood. They mostly had keywords or methods I wasn't familiar with. Anyway, here's where I am so far.
class Program {
static string UpperCase(string s) {
int place; string b, st1, st2,st3; char letter;
for (int i = 0; i <= s.Length - 1; i++) {
if (i == 0) {
[Code]....
The code compiles without any errors, but when I enter a string it capitalizes correctly for the first two words and then it starts capitalizing letters in the middle of the words.
View 14 Replies
ADVERTISEMENT
Nov 14, 2014
I've been agonizing over this all day. The assignment is to capitalize every other word in a user input string.
My logic is as follows:
1. I have the program get each character until it encounters white space (using for loop)
2. Then it should capitalize each character after the white space until it encounters another white space (using while loop).
My problem though is when i try to create a condition for while loop i have to terminate is when white space is encountered, but the very first character to start the while loop is a white space..
I was told to define boolean values, but after trying a few boolean conditions I'm still stuck..
Code:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
[Code] .....
View 5 Replies
View Related
Oct 28, 2014
Can I capitalize first letter of each word without using arrays ? If yes, how can I ?
View 11 Replies
View Related
Jul 25, 2013
The assignment is to read a data file with a list of names, capitalize the first character of the first and last name by making an array and subtracting 32 from the character, and then outputting the names onto the screen. So far I have:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("Names.txt");
[Code] ....
this allows me to read a name, and capitalize the first letter of the first name. How to capitalize the first letter of the last name.
View 2 Replies
View Related
Aug 22, 2014
I have one string from user. Let say,
"The deviceId is 2"....but user also can give input like this..
"The deviceId is a".
I just need to know how to differentiate a word/letter and number in the string.
View 1 Replies
View Related
Dec 10, 2014
Write a program that inputs a string and then converts each 1st letter of a word in the string into capital case. An example run of the program is shown below:
Enter string: introduction to programming
Output string: Introduction To Programming
View 1 Replies
View Related
Mar 16, 2013
im trying to capitalize every other word. for examples input: hello output: HeLlO
View 5 Replies
View Related
Mar 1, 2015
So this is my homework: a user will enter a line of text, echo the input one word per line and capitalize each word(do not use toupper) and also needs word count and punctuation marks count. I know how to echo one word per line. How to capitalize each word without toupper? and how to do word count?
View 3 Replies
View Related
Feb 26, 2013
I'm trying to write a program that capitalizes every other word of a user output. (ex: if input is "i love you", the output is "i LoVe YoU").
I am using a for loop (although an if loop might be easier?) and I'm assuming that it is possible to write this program using a for loop (although I may be wrong--maybe only if loops can write this program). I have everything down EXCEPT the last step where I have to print the entire sequence. What i have so far is:
Code:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
{
// get user input
printf("Type a sentence: ");
string s = GetString();
[Code] .....
The code above basically only prints out the capital letter (ex: input is "hello", output is "EL"). I don't know how to print out the entire sequence.
View 2 Replies
View Related
Dec 27, 2013
I want a program to display as follows..
if i enter mohandas karamchand gandhi i want output as M K Gandhi.....
i want the c++ code for this program..my error is i am not able to erase the letters of first 2 words..ie my output is Mohandas Karamchand Gandhi..
View 2 Replies
View Related
Mar 30, 2014
I need to reverse a word . For instance "Hello" after reversing will be "olleh" . It reverse first and last letter but its not reversing the rest of them
char arr[]="Hello";
int first=0;
int last=sizeof(arr-1);
int mid=sizeof(arr)/2;
[Code] ....
View 2 Replies
View Related
May 31, 2013
Write a function that accepts a pointer to a C-String as an argument and capitalizes the first character of each sentence in the string. For instance, if the string argument is "hello. my name is Joe. what is your name?" the function should manipulate the string so it contains "Hello. My name is Joe. What is your name?" Demonstrate the function in a program that asks the user to input a string and then passes it to the function. The modified string should be displayed on screen. Optional Exercise: Write an overloaded version of this function that accepts a string class object as its argument.
#include<iostream>
#include<cctype>
#include<cstdlib>
using namespace std;
void capitalize(char sentence[], int const SIZE);
[Code]...
Not even sure if I'm headed in the correct direction, but I'm getting the following errors:
E:CPT-233Sentence Capitalizer.cpp In function `void capitalize(char*, int)':
34 E:CPT-233Sentence Capitalizer.cpp call of overloaded `strstr(char&, const char[2])' is ambiguous
note E:CPT-233<internal>:0 candidates are: char* std::strstr(const char*, const char*) <near match>
note E:CPT-233<internal>:0 char* std::strstr(char*, const char*) <near match>
what I'm doing wrong?
View 2 Replies
View Related
Sep 22, 2013
I need to write a C program to make the user input some text,and the first letter of each word has to be uppercase.(have to use while loops)So for example lets say the user inputs:
i lOvE pRoGrAmMiNg
The output needs to be:
I Love Programming
Code:
#include <stdio.h>
int main()
{
int i = 0;
char c, lower_c;
printf("Enter text
");
[code]....
I have started this code by making the letters lowercase.I am not sure how proceed after this step, the step of making the first letter uppercase.
View 2 Replies
View Related
Jan 21, 2013
I just would like to turn this into cpp:
string eg("azertyFTW");
if(eg[one of the letters contained in this string] == 'c') {
cout << "eg has the letter c in it";
} else {
cout << "not this time :(";
}
View 4 Replies
View Related
Apr 28, 2013
tell me how to loop through a string and uppercase each letter?
View 1 Replies
View Related
May 16, 2014
I have a problem with my code. You are given a sentence and you should censor the 4 letter words within the sentence.
#include<iostream>
#include<string>
using namespace std;
int main () {
int N;
cin>>N;
int k,j,counter=0;
[Code] ....
View 1 Replies
View Related
Feb 3, 2015
I need a code that will search through string 1 and find the first place with a letter that also appears in string 2 and return the pointer of that place. This is what I wrote:
char strPbrk(const char *s1, const char *s2) {
char p = *s1;
for (int i = 0; i < strlen(s1); i++)
for (int j = 0; j < strlen(s2); j++)
if ((p+i) == *(s2+j))
return p;
return NULL;
}
but it continues to return wrong values idk what I'm doing wrong.
View 4 Replies
View Related
Jan 29, 2013
I need a simple adjacent_find() to find the adjacent same letter in a randomly generated string?
View 1 Replies
View Related
Nov 18, 2013
I would like to know how I can know if a word is before another in a string. Here's my current code.
#include <iostream>
#include <math.h>
#include <string>
#include <cstdlib>
#include <sstream>
#include <vector>
#include <iterator>
using namespace std;
int main() {
string equation;
getline (cin, equation);
[Code] .....
View 9 Replies
View Related
Apr 12, 2013
1. Create a variable named index and nitialize it to zero(0)
2. Prompt for and input a string value from thekeyboard. Store the string inthe string variable newstring[80].
3. While (newstring[index] does not equal ‘ ’).
i. Display the character at newstring[index] followed by a NL
ii. Increment index ====================================== ...
And this is what i have done so far and i dont know where I am wrong ...
Code:
#include<stdio.h>
int main()
{
int index = 0; //initialize index to zero since first elementin an array is numbered zero
char newstring[80];
[Code] ....
View 3 Replies
View Related
Mar 2, 2014
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
//Program Goal
//Have 3 Strings to represent 3 categories
//Have the user type in their name
//Have the user type in a full sentence how they are feeling
//Program should find the word in the user inputted sentence and display an appropriate response
[Code]...
View 4 Replies
View Related
Apr 3, 2013
I want to see if the value of a string equals a certain text. But I can't make it. There are two problems :
1) It seems 'tolower' doesn't work with strings. What to use then?
2) When I delete tolower, it works, but I have an output of "You didn't enter 'add'" even when I do enter 'add'. What's the problem? Is it due to the null byte? What to change?
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) //This was added automatically by Visual Studio.
[Code] .....
View 3 Replies
View Related
Mar 5, 2014
I'm trying to read a string and then compare it to a word.
My code:
char* cmd = "start";
std::cin >> cmd;
if (strcmp (cmd, "eval"))
eval ();
When the program gets to the cin part, it breaks.
View 4 Replies
View Related
Dec 9, 2013
I'm having trouble trying to turn a word into letters. I've seen other posts but they deal with a sentence and it only outputs the words only. What I want to know is how do they take a word (Ex: "word") and break it into individual letters, where I want to store them in a vector of string?
If it's not too much trouble, I would prefer without using pointers or "std:: " marks, since I am trying to avoid pointers and I'm using "using namespace std" all the time.
Ex:
In the example "word", it should output into:
"w"
"o"
"r"
"d"
and I will push them back into a vector of string where each vector element contains a letter.
View 2 Replies
View Related
Dec 20, 2014
I have been trying to get this to work for a while now - with no success.
Basically I am trying to write a function which the returns the first word of each input sentence in a single string - this is part of a larger cryptography program I am working on.
So for example, if this string was passed into the function:
"This is what I mean. Is it right? A poor puppy abandoned. Secret torturing of dogs are happening. Message: be on the watch."
It should return:
//declared in class "steganalyse"
string cyphertext;
string punctuation = ".?!;:'";
book is_first_word
[Code] .....
But this only returns the first word:
This
Any other way to return the first word of each sentence in a string.
View 1 Replies
View Related
Apr 29, 2015
How to find the last longest word in a string when there are more of them (with the longest size)?
Here is the program for the longest without checking if last:
#include<stdio.h>
#include<string.h>
int main() {
char a[50],b[20],c[20];
int i,j=0,l=0;
printf("Enter a string:
");
gets(a);
[Code] ....
View 6 Replies
View Related