[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

String functions

Posted on 2000-01-23
10
Medium Priority
?
197 Views
Last Modified: 2010-04-02
Experts,
        I am just starting to explore into the STL library and had questions about some inbuilt functions.

(1) How do I convert all the characters in a string to lower-case.
(2) How do I remove blank lines between words in a string
(3) How do I convert 2 words (part of a string) which are both in small caps into one where the first character in each word has large caps.
0
Comment
Question by:gvijay1
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:dhymes
ID: 2380809
0
 

Accepted Solution

by:
roupik earned 60 total points
ID: 2380830
i=0;
while (*(string+i)) TOLOWER(string+i++);


0
 
LVL 2

Expert Comment

by:dhymes
ID: 2381089
roupik, This is not the way we play the game out here, you should not answer after someone else has added a comment. Also when you answer a question you need to answer the whole question.  
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:gvijay1
ID: 2383796
Roupik,
       To which of the above questions, is this answer. Please let me know
0
 

Author Comment

by:gvijay1
ID: 2383871
Roupik,
       Well, I figured out to which question that was and wrote a small code to see how it worked but the function did not work. Please let me know what you think the error iss..

//Code is Below
#include <iostream>
#include <string>
#include <vector>
#include <set>


main()
{
string Word;

cout<<"Enter the word here..."<<endl;
cin>>Word;

int i=0;

while (*(Word+i))
{
      TOLOWER(Word+i++);
}

cout<<"The new word is..."<<Word<<endl;

return 0;

}
0
 

Expert Comment

by:roupik
ID: 2384408
problem is in TOLOWER(word+i++);

we need word+i before i++, but i++ runs eary :o( - so,
{ TOLOWER(word+i); i++; } can help

maybe ;o)

for(i=0;*(word+i);i++) TOLOWER(word+i);
0
 

Author Comment

by:gvijay1
ID: 2386523
Roupik,
       It is still giving me the same error and it is..C forbids comparison between an integer and a pointer. HMMMM!!!! I also included the ctype.h library, but it too does not work..Please give me further suggestions if possible.

0
 

Author Comment

by:gvijay1
ID: 2386664
Roupik,
       It is still giving me the same error and it is..C forbids comparison between an integer and a pointer. HMMMM!!!! I also included the ctype.h library, but it too does not work..Please give me further suggestions if possible.

0
 

Author Comment

by:gvijay1
ID: 2386665
Roupik,
       It is still giving me the same error and it is..C forbids comparison between an integer and a pointer. HMMMM!!!! I also included the ctype.h library, but it too does not work..Please give me further suggestions if possible.

0
 
LVL 3

Expert Comment

by:3rsrichard
ID: 2386791
Try starting with something less elegant


// Funtest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <conio.h>
#include <ctype.h>
#include <string.h>

int main(int argc, char* argv[])
{

      char InString[80] = {78};
      char OutString[80];
      char *result;
      int i;
      int j;

// 1
      cprintf("Enter the string here ");
      result = _cgets(InString);
      printf( "\nLine length = %d\nText = %s\n", InString[1], result );

 
      for( i=0;i<InString[1];i++)
      {
            OutString[i] = tolower(InString[i+2]);
      };
      OutString[i] = 0;
      
      cprintf("\n\nThe new word is...     %s\n\n",OutString);


//2

      for( i=0,j=0;i<InString[1];i++)
      {
            OutString[j] = tolower(InString[i+2]);
            if(InString[i+2] != ' ')
                  j++;
      };

      OutString[j] = 0;
      
      cprintf("\n\nThe new word is...     %s\n\n",OutString);


//3
      OutString[0] = toupper(InString[2]);
      for( i=1;i<InString[1];i++)
      {
            OutString[i] = tolower(InString[i+2]);
            if(InString[i+1] == ' ')
                  OutString[i] = toupper(InString[i+2]);
      };

      OutString[i] = 0;
      
      cprintf("\n\nThe new word is...     %s\n\n",OutString);

return 0;


}

0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question