Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

Program Discussion :: Basics
Home > Programs > Basics

9.  Write a program to converting a String to Sentence Case.
Hint: In sentence case, the first letter of each sentence is capitalized. 

Answer:

#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();
}

Post Your Answer Here:

Name *
Email

rai said:Sat, April 22, 2017, 11:19:45 am

Language:

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]);
            }
    }
}
}

Post Your Reply Here:



rai said:Sat, April 22, 2017, 11:20:31 am

Language:

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));
   }
}

Post Your Reply Here:



Monika said:Sun, June 11, 2017, 1:41:54 am

Language:

<!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>

Post Your Reply Here:



Kanika said:Thu, July 6, 2017, 9:00:45 pm

Language:

#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]);
        }
     }

Post Your Reply Here:



Neha said:Thu, July 6, 2017, 9:00:45 pm

Language:

#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();
}

Post Your Reply Here: