Letter-cases

What would you like to see in CSPro?
Forum rules
New release: CSPro 8.0
arkagwa
Posts: 119
Joined: November 18th, 2014, 5:25 am

Letter-cases

Post by arkagwa »

Dear developers

The current feature allows two cases for letters; lower letters and upper/capital letters. Sometimes the variable captures three names or two words where you need the initials with capital letters, example Andrew Raphael,....Letters A and R (initials) are capital. This feature is missing

If there is alternative solution kindly help, i find it difficult for data entrants switching cases in keyboard :( :(

Good evening
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Letter-cases

Post by josh »

Why not just tell the enumerators to use all lower case or all upper case? You can convert to mixed in case in logic if you really need it although in many cases it is not needed. To convert to mixed case just have a loop through the string and each time you find a space you capitalize the next letter.
arkagwa
Posts: 119
Joined: November 18th, 2014, 5:25 am

Re: Letter-cases

Post by arkagwa »

Dear Josh

Can you assist me with the code for looping the string to capitalize every first letter.......please i would appreciate very much :) :)
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Letter-cases

Post by josh »

Try Googling "capitalize first character of each word in string". That will show you some examples in other programming languages that you can adapt to CSPro.
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Letter-cases

Post by htuser »

Hi Josh,
I find this code for the same purpose:

Code: Select all

#include <stdio.h>
#define MAX 100

int main()
{
	char str[MAX]={0};	
	int i;
	
	//input string
	printf("Enter a string: ");
	scanf("%[^\n]s",str); //read string with spaces
	
	//capitalize first character of words
	for(i=0; str[i]!='\0'; i++)
	{
		//check first character is lowercase alphabet
		if(i==0)
		{
			if((str[i]>='a' && str[i]<='z'))
				str[i]=str[i]-32; //subtract 32 to make it capital
			continue; //continue to the loop
		}
		if(str[i]==' ')//check space
		{
			//if space is found, check next character
			++i;
			//check next character is lowercase alphabet
			if(str[i]>='a' && str[i]<='z')
			{
				str[i]=str[i]-32; //subtract 32 to make it capital
				continue; //continue to the loop
			}
		}
		else
		{
			//all other uppercase characters should be in lowercase
			if(str[i]>='A' && str[i]<='Z')
				str[i]=str[i]+32; //subtract 32 to make it small/lowercase
		}
	}
	
	printf("Capitalize string is: %s\n",str);
	
	return 0;
}
And it seem difficult to port it to Cspro Programming Language... I can't "translate"
#define MAX 100
scanf("%[^\n]s",str); //read string with spaces
char str[MAX]={0};
str!='\0';


Please can you help us?

In the future when we can use C/C++ functions/methods/classes inside Cspro Logic, this will open an univers for Csprousers.

Thanks in advance!
G.VOLNY, a CSProuser from Haiti, since 2004
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Letter-cases

Post by josh »

You don't need the scanf part. That part is reading the string that user types in. The important part starts from the for loop.
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Letter-cases

Post by htuser »

Hi Josh,
I'm trying to port this code and here's the results...with errors...
Please, can you help me to correct!

Thanks in advance,
CapitalizeString.zip
(2.65 KiB) Downloaded 320 times
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Letter-cases

Post by Gregory Martin »

Your code does some things it doesn't need to like use \0, which is not needed in CSPro. You can write this logic pretty simply using CSPro functions:
function string capitalizeEachWord(string text)

    numeric next_non_blank_letter_should_be_capitalized = 1;

    do numeric ctr = 1 while ctr <= length(text)

        string this_letter = text[ctr:1];

        if this_letter = " " then
            next_non_blank_letter_should_be_capitalized = 1;

        elseif next_non_blank_letter_should_be_capitalized = 1 then
            text[ctr:1] = toupper(this_letter);
            next_non_blank_letter_should_be_capitalized = 0;

        else
            text[ctr:1] = tolower(this_letter);

        endif;

    enddo;

    capitalizeEachWord = text;

end;
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Letter-cases

Post by htuser »

Thank you Greg. Since Cspro have powerful functions, i had to think in Cspro, not trying to "translate".
Best Regards,
G.VOLNY, a CSProuser from Haiti, since 2004
arkagwa
Posts: 119
Joined: November 18th, 2014, 5:25 am

Re: Letter-cases

Post by arkagwa »

Does not work for me ...keep asking for ; operator
Is word "text" a syntax or used as variable??
Post Reply