Program Discussion :: Basics
9 / 279
Write a program to converting a String to Sentence Case.
Hint: In sentence case, the first letter of each sentence is capitalized.
Answer:
#include
#include
#include
#include
void main()
{
clrscr();
int i;
char a[30];
cout
Asked In ::
Language:

Rai
22 Apr, 2017 11:49 PM
import java.io.*;
import java.util.regex.*;
public class SentenceCase{
public static void main(String []ar)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
System.out.print(str.substring(0,1).toUpperCase());
char []arr=str.toCharArray();
for(int i=1;i<arr.length-1;i ){
if(arr[i]=='.'){
char temp=Character.toUpperCase(arr[i 2]);
i=i 2;
System.out.print(". " temp);
}
else{
System.out.print(arr[i]);
}
}
}
}
Language:

Rai
22 Apr, 2017 11:50 PM
import java.util.Scanner;
public class CaseManipulation {
public static String toSentenceCase(String inputString) {
String result = "";
if (inputString.length() == 0) {
return result;
}
char firstChar = inputString.charAt(0);
char firstCharToUpperCase = Character.toUpperCase(firstChar);
result = result firstCharToUpperCase;
boolean terminalCharacterEncountered = false;
char[] terminalCharacters = {'.', '?', '!'};
for (int i = 1; i < inputString.length(); i ) {
char currentChar = inputString.charAt(i);
if (terminalCharacterEncountered) {
if (currentChar == ' ') {
result = result + currentChar;
} else {
char currentCharToUpperCase = Character.toUpperCase(currentChar);
result = result currentCharToUpperCase;
terminalCharacterEncountered = false;
}
} else {
char currentCharToLowerCase = Character.toLowerCase(currentChar);
result = result + currentCharToLowerCase;
}
for (int j = 0; j < terminalCharacters.length; j++ ) {
if (currentChar == terminalCharacters[j]) {
terminalCharacterEncountered = true;
break;
}
}
}
return result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an input String: ");
String inputString = scanner.nextLine();
System.out.println("Title Case: "+ toSentenceCase(inputString));
}
}
Language:

Monika
11 Jun, 2017 2:11 PM
<!DOCTYPE html>
<html>
<body>
<?php
function Sentence_case() {
// input string
$arr ="what is your name";
echo "Input string is :" . $arr."<br/>";
// function to convert in Sentence_case
$camel =ucfirst ($arr) ;
// printing string in Sentence_case
echo $camel;
}
// function calling
Sentence_case() ;
?>
</body>
</html>
Language:

Kanika
7 Jul, 2017 9:30 AM
#include <stdio.h>
#include <iostream>
void main() {
char sentence[100];
int i;
printf("Enter your name and surnames: ");
gets(sentence);
for(i = 0; i<strlen(sentence); i++){
if(sentence[i] == ' '){
printf("%c", toupper(sentence[i]+1));
/* I want to advance to next item respect to space and capitalize it */
/* But it doesn't work */
} else {
printf("%c", sentence[i]);
}
}
}
Language:

Neha
7 Jul, 2017 9:30 AM
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
void main()
{
clrscr();
int i;
char a[30];
cout<<“Enter a string:”;
gets(a);
for(i=0;a[i]!=’’;++i)
{
if(i==0)
{
if(islower(a[i]))
a[i]=toupper(a[i]);
}
else
{
if(a[i]!=’ ‘)
{
if(isupper(a[i]))
a[i]=tolower(a[i]);
}
else
{
i++;
if(islower(a[i]))
a[i]=toupper(a[i]);
}
}
}
cout<<“nnNew string is: “<<a;
getch();
}